So I'm trying to get my program to be able to have a txt file piped though in shell, and just put out the non-empty lines for an assignment. I scrapped the first one that I was working on and this is take 2, but it comes up with a segment fault. I have to use #C so I can't use std::
For this to work ( c = getchar() ) != EOF, c must be an int.
And what is this? strcmp(a, c)
In C, the simple way to read a line from stdin is to use fgets()
1 2 3 4 5 6 7 8 9 10 11
#include <stdio.h>
int main()
{
enum { MAX_CHARS = 8192 } ;
staticchar line[MAX_CHARS] ;
while( fgets( line, MAX_LEN, stdin ) ) // for each line till eof
if( line[0] != '\n' ) // if it is not an empty line
printf( "%s", line) ; // print it out
}