Hi All,
I have a problem, I construct a string in a loop and the output of that string to stout displays the string and a character 'y' with two dots above it as the last character.
What is that?
I create the string in this function:
char get_string(char *buf, int ble, FILE *fp, char del)
{
int i = 0;
int c;
char result;
memset(buf, 0, BUFLEN);
do {
c = fgetc(fp);
if (c == del) {
buf[i] = '\0';
result = c;
break;
} else if(c == '\n') {
buf[i] = '\0';
result = '\n';
break;
} else {
buf[i] = c;
i++;
}
} while (c != EOF);
return result;
}
and then use the buf and result as follows in another function:
char pair[BUFLEN];
char end;
do {
end = get_string(pair, BUFLEN, fp, ';');
printf("Result: %s\n",pair);
} while (pair != NULL);
The last iteration of the above Prints out "Result: y" I have no idea why.