Question: C PROGRAMMING Problem: A simple cat-like program which opens a file whose name is on the command-line, and copies its contents to stdout. Code: #include
C PROGRAMMING Problem:
A simple cat-like program which opens a file whose name is on the command-line, and copies its contents to stdout.
Code:
#include
int main(int argc, char **argv)
{
FILE *fp;
char c;
if (argc < 2)
printf("put a file name");
fp = fopen(argv[1], "r+");
while ((c = getc(fp)) > 0)
putchar(c);
fclose(fp);
return(1);
}
Submit your improved program in a file named "lab08.c".
Your should not add or change anything which is not specifically to fix a defect in the above program. However, your program should behave like a proper unix program -- for example, one of the defects above is the incorrect exit status. Its error handling and message(s) are also wrong.
Programs which do not compile with "gcc Wall" with no errors or warnings will not get the mark for this lab. However, this is not the only cleanup required. I count ten defects above (although it does depend on how you count), of which you must fix at least six (without introducing any new defects nor changing anything irrelevant) to get the mark.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
