What happens when in C I do something like:
char buf[50]="";
c = fgetc(file);
buf[strlen(buf)] = c+'\0';
buf[0] = '\0';
I'm using some this code in a loop and am finding old values in buf I just want to add c to buf
I am aware that I can do:
char s=[5];
s[0]=c;
s[1]='\0';
strcat(buf, s);
to add the char to buf, but I was wondering why the code above wasn't working.
c+'\0'is justc. It does not write two elements to the array.buf[0] = '\0';resetbufto null-string("").