Write a C program that will read bytes from stdin until EOF, discarding all bytes that are not equal to 0xEF, and writing the 0xEF bytes to stdout. Put your source code in the file lab1.c.
You should include stdio.h and use the standard C functions getchar and putchar to do the I/O. Be aware that you should put the return vaue of getchar into an int (and not a char) in order to properly detect EOF.
Compile your program in the following manner:
gcc -g -Wall lab1.c -o lab1
You may need to write another C program in order to create an interesting test file.
The input and output may not be ASCII so you may want to use the od tool (type: man od) to examine both input files and output files. In particular, the -tx1 flag will display a file one byte at a time in hex.
Use standard redirection on the command line to connect files to stdin
and stdout:
lab1 < inFile > outFile.
Use gdb to step through your program, examine your variables, etc. You probably won't need it to debug this lab, but you will need it later so learn its basic features now, if you don't know/remember them.
To turn in this laboratory, type:
Submissions can be checked by typing:
15 points will be awarded for correctly reading the input and
detecting EOF.
15 points will be awarded for writing the correct output file.
Remember that 70 points will be awarded for attendance, but if
you do not attend your score on the 30 other points will be
prorated to 100 points.
Comments and questions should be directed to
hatcher@unh.edu
~cs520/bin/submit lab1 lab1.c
~cs520/bin/scheck lab1
Last modified on January 25, 2012.