#include #include // This program prints the contents of a file but skips the lines // starting with # (the # symbol is sometimes used to denote comments). // The code uses fgets to read each line into a char array called BUFFER. // BUFFER is analysed and if the first character is a # the line is not printed. // The program has a small bug with comment lines that have leading whitespace // before the # character. This bug is fixed in the netx program. int main() { FILE *fp; char BUFFER[1024]; int a, b; fp = fopen("text.txt", "r"); // one the file for reading if(fp == NULL) printf("File not found!\n"); else { while( fgets(BUFFER, 1024, fp) != NULL) // read at most 1024 characters from fp and store them in BUFFER { if(BUFFER[0] != '#') printf("%s", BUFFER); } fclose(fp); } system("pause"); }