Anonymous
PO
I'm still stoped since saturday in my project.
I'm making a OXO game
And I have to write a function to count the times of clicking like that I can switch the game between O player and X player.
I have tried several things and now I'm lost
I can detect each click but I can't increment value
Andrew
PO
I detect each click like that
gboolean btn_press_callback(GtkWidget *btn, GdkEventButton *event, gpointer userdata){
if (event->type == GDK_BUTTON_PRESS && event->button == 1){
printf("click left\n");
return TRUE;
}else{
return FALSE;
}
}
Anonymous
I know this is a c/c++ channel, but what are your opinions on rust? I just started learning it
Anonymous
Hello I am new on this group
Anonymous
I want to learn C from basic level
Anonymous
Can anybody gives me the algorithm of finding HCF and LCM of given numbers
Roxifλsz 🇱🇹
>the only high level language that is compiled to machine code
Nope, the largest other such langs are go and dart (and maybe swift?), and there are many others, just less known
Anonymous
Anonymous
Sasuke
Anonymous
What does %d , %e signifies in c. At what case we should use %d and %e...
Anonymous
%d if for integer values in format strings and i believe %e was for scientific notation, but im not sure on that
Vlad
Janko Ⓥ
Sasuke
Anonymous
Lol ofc.
Vlad
%f is for floats
Anonymous
sry my bad
Anonymous
Messed that up somehow, shame on me ^^
Anonymous
Thank you all
Anonymous
So yeah the usage is for format strings like in printf where the 1st argument is a format string and these escape sequences can be used to read a value of a certain type.
Anonymous
example: printf("hello %d", 1); would just print "hello 1" to the console. Im unsure about if the scientific notation should be supplied as a cstring (i think one should) but yeah better look that up. I even messed up %d and confused it for %f 😅😅
Vlad
https://en.cppreference.com/w/cpp/io/c/fprintf
Vlad
Documentation exists btw
Anonymous
/warn
Anonymous
Vlad
Any for C
cppreference has dedicated C documentation
Anonymous
Anonymous
Janko Ⓥ
Nice
You're looking at messages from 2017?
Ehsan
xx.cpp:66:7: error: object of type 'String' cannot be assigned because its copy assignment
operator is implicitly deleted
x = "Hi";
^
xx.cpp:54:9: note: copy assignment operator is implicitly deleted because 'String' has a
user-declared move constructor
String(String&& rval){
^
1 error generated.
Ehsan
anyone knows what is happening?
Ehsan
Anonymous
which one did I violate?
The compiler doesn't define copy assignment and copy constructor by default when you explicitly define move constructor.
Vlad
And also copy and move assignment
Vlad
You can just = default them
Ehsan
oh
Ehsan
omg how did I forget so stupid.
Mohamed
/* A Slightly Less Simple PThreads Example */
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS 4
void *threadFunc(void *pArg) { /* thread main */
int *p = (int*)pArg;
int myNum = *p;
printf("Thread number %d\n", myNum);
return 0;
}
int main(void) {
int i;
pthread_t tid[NUM_THREADS];
for(i = 0; i < NUM_THREADS; i++) { /* create/fork threads */
pthread_create(&tid[i], NULL, threadFunc, &i);
}
for(i = 0; i < NUM_THREADS; i++) { /* wait/join threads */
pthread_join(tid[i], NULL);
}
return 0;
}
Mohamed
the output is sometimes
Thread number 0
Thread number 0
Thread number 0
Thread number 0
Mohamed
can anyone reason about this?
how can all the threads read the value of the i = 0 while they are created as i increments
Vlad
Vlad
No it doesn't I'm blind
Mohamed
Vlad
But anyway. You pass an address of an exact variable
*
https://www.urionlinejudge.com.br/judge/en/problems/view/1021
*
Vlad
Vlad
And that set isn't atomic so you've got a data race
Vlad
And it's UB at this point
Vlad
So you'd have to create an array of those integers and copy your i to the respective element of an array and then pass an address of that element
Mohamed
Mohamed
I was shocked how all the threads read the value 0
Mohamed
Vlad
Vlad
Before that there's no guarantee
Vlad
Even if you wouldn't set it to zero and let's say would've used another variable as a counter. You'd still have an issue that your loop writes to that variable
Vlad
Anonymous
#include<iostream>
using namespace std;
int main() {
string s;
cin >> s;
puts((s.find("0000000")+1||s.find("1111111")+1)?"YES":"NO");
}
Can anyone tell why we add 1 in s.find("0000000")?
anko
Hey guys help please, how can i read from a txt file containing data in strings, separated by tab into an array of structure in C
anko
while (fgets(str, sizeof(courseSem1Yr1), coetSem1Year1Fptr) != NULL)
{
readDetail = strtok(str, "\t");
strcpy(courseSem1Yr1[i].module_code, readDetail);
readDetail = strtok(NULL, "\t");
strcpy(courseSem1Yr1[i].module_title, readDetail);
readDetail = strtok(NULL, "\t");
courseSem1Yr1[i].credit = atoi(readDetail);
printf("%s\t%s\t%d\n", courseSem1Yr1[i].module_code, courseSem1Yr1[i].module_title, courseSem1Yr1[i].credit);
i++;
}
anko
while (fgets(str, sizeof(courseSem1Yr1), coetSem1Year1Fptr) != NULL)
{
readDetail = strtok(str, "\t");
strcpy(courseSem1Yr1[i].module_code, readDetail);
readDetail = strtok(NULL, "\t");
strcpy(courseSem1Yr1[i].module_title, readDetail);
readDetail = strtok(NULL, "\t");
courseSem1Yr1[i].credit = atoi(readDetail);
printf("%s\t%s\t%d\n", courseSem1Yr1[i].module_code, courseSem1Yr1[i].module_title, courseSem1Yr1[i].credit);
i++;
}
i did like this but and am getting correct data but the problem is after compilation process it bright some dialog error message from vscode as shown below and i don't want to see that message. how to solve this or if there any better solution apart from that
anko
Unable to open 'strcpy-avx2.S': Unable to read file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/x86_64/multiarch/strcpy-avx2.S' (Error: Unable to resolve non-existing file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/x86_64/multiarch/strcpy-avx2.S').
anko
Mohamed
Otumian
It is about time you have a separate group for noobs
klimi
Anonymous
guys
Ehsan
Anonymous
i know some language and i use python c and c++ for hacking(backdoors and exploits) now i have a question.
c# is good too?
klimi
Andrew