I am trying to add a null termination to my buffer with the following code. But I don’t seem to be able to pass my null terminator in.Is this the correct way to do it? When I strlen my buffer the value is 10 but I only keyed in 9 chars.
char buffer[256];
int n;
bzero(buffer,256);
fgets(buffer,255,stdin);
buffer[n-1]="\0";
You are assigning a string not a char with
buffer[n-1] = "\0";.Try
buffer[n-1] = '\0';instead.