|
From: Eduardo R. <reb...@gm...> - 2004-12-21 03:41:36
|
Hi everybody,
I'm trying out the following piece of code:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
char word[100];
if((fp = fopen("mystuff.txt", "r")) == NULL) {
printf("Error while opening file");
exit(1);
}
while(!feof(fp)) {
fscanf(fp, "%s", &word);
printf(" %s ", word);
}
return 0;
}
I've had problems with this program when "mystuff.txt" has a phrase
which ends with a blank space. In this case, the program outputs the
last word twice. Can anyone point me a way to correct such a
unexpected behavior?
Thanks in advance,
---
Rebellis
|