COMP 206 Lecture Notes - Lecture 16: Data File, Carriage Return, Scanf Format String
Document Summary
Eof: end of file is returned by input functions when they can no longer give useful input. Usually used to end lines in unix text files. \r: carriage return ( mainly not used in unix ) Can read single character from a file, but we must have some error messages ex. If the next character is the end of a file. Always check to make sure file pointer is not null. All scanf returns the number of things" it has read for you (however many of the %(d,s,etc. ) exist) Tests to end reading in order to end the reading of a while loop, you must use eof while (((c = getchar()) != \n) && (c != eof) putchar(c); if(c != eof) putchar(c); Read until end of file: while((c=getchar()) != eof) Read from a file until end of file: while((c=fgetc(filehandle)) != eof) Read until end of line: while ((c = getchar()) != \n)