Can anyone tell me what's wrong with my program below?
I'm creating a program that writes every character(byte) from a buffer to a FILE until the number of bytes written is equal to the size of the buffer.
char *next;
int character;
int byteswritten = 0;
next = buf; //buf is the buffer that holds the string to be written on a FILE
while (byteswritten < payload) { //payload is the size of the buffer
character = fputc(*next, fp); //fp is the FILE where the contents of buf will be written to
byteswritten++;
next++;
}
The problem of my program above is when *next encounters a NULL in the middle of the buffer, everything else written on the FILE is NULL but in reality non-NULL characters still follow the NULL character. How could I fix this? Big big thanks to anyone who could answer my question.