MP0 Q&A
How to write to standard error?
This is the easiest one. Of course, there are alternatives.
fprintf(stderr, "error\n");
Good compilation practices
With -Wall
option, GCC compiler produces warnings about constructions that some users consider questionable. This helps avoiding bugs in your code.
gcc -o char_count char_count.c -Wall
How to terminate your program if it hangs
Press ^C (Ctrl-C) or ^\ (Ctrl-\). The process will receive SIGINT or SIGQUIT signal. If neither of these works, start another terminal and run killall -KILL char_count
.
How to generate input for testing
yes
, head
, tail
, grep
, shuf
commands are friends. See manpages for detailed usage. For example, man yes
shows to manual for yes
command.
To test a file with 1000 line of text,
yes | head -n 1000 > FILE.txt
./char_count "ab c" FILE.txt
To feed your program with infinitely many lines,
yes | ./char_count