While it's not good programing practice and heaven knows there is a lot wrong with the bit of code that can be seen, it will work.
int main(int argc, const char * argv[])
{
@autoreleasepool {
FILE *fp;
char chars;
if ((fp = fopen("/Users/frank/text.txt", "r" )) == NULL) {
NSLog(@"Open Failed");
return(-1);
}
while ((chars = fgetc(fp)) ) {
if (chars == '\n')
NSLog(@"new line\n");
else if (chars == EOF) {
NSLog(@"end of file\n");
return(EXIT_SUCCESS);
} else
NSLog(@"*%c*",chars);
}
NSLog(@"end of while");
}
return0;
}
produces
2013-03-09 13:40:38.402 ASCfgetcTST[10809:303] *a*
2013-03-09 13:40:38.404 ASCfgetcTST[10809:303] *b*
2013-03-09 13:40:38.404 ASCfgetcTST[10809:303] *s*
2013-03-09 13:40:38.404 ASCfgetcTST[10809:303] *c*
2013-03-09 13:40:38.405 ASCfgetcTST[10809:303] *e*
2013-03-09 13:40:38.405 ASCfgetcTST[10809:303] *f*
2013-03-09 13:40:38.406 ASCfgetcTST[10809:303] new line
2013-03-09 13:40:38.406 ASCfgetcTST[10809:303] *h*
2013-03-09 13:40:38.406 ASCfgetcTST[10809:303] *i*
2013-03-09 13:40:38.407 ASCfgetcTST[10809:303] *j*
2013-03-09 13:40:38.407 ASCfgetcTST[10809:303] *k*
2013-03-09 13:40:38.407 ASCfgetcTST[10809:303] new line
2013-03-09 13:40:38.408 ASCfgetcTST[10809:303] end of file
from a file of
cat text.txt
abscef
hijk
One nice thing about computers, you can ask them somehting and they will always tell you the truth (as far as their workings go)