Hi guys!
My program basically reads from a text file or whatever is piped into it through std in and I need to catch a read error, but I'm confused on what to even look for exactly.
Someone would run my program like this:
myProgram < aTextFile.txt
Here is some of my code what does the reading:
As you can see i'm just using getc to read each character, but what would I check if there was an error reading the file? if an error did occur I would just exit(1) but what to check for is where I'm lost.Code:while ((c = getc(stdin)) != EOF) 76 { 77 /*counting characters*/ 78 characters++; 79 80 /*counting special characters*/ 81 if(isprint(c) != 0) 82 printable++; 83 if(iscntrl(c) != 0) 84 { 85 control++; 86 } 87 if(c == '\n') 88 newline++;
Thanks!