> the problem is foo is end in "LF" ( 0A ), and it will let a.out > get wrong output. if i run > > #a.out > > and input data from keybord, then end it by ctrl+D, will get the > right answer. > i'm not sure, if i understand you right ... you are having trouble to detect the end of file, when there is an empty line at it's end, right?
i didn't test it, but this should be the default way of doing it: FILE *fd; char buf[1000]; while(!feof(fd)) { fgets(buf,sizeof(buf),fd); } -- Hi! I'm a .signature virus! Copy me into your ~/.signature, please! -- Linux - the last service pack you'll ever need.