Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

can someone tell me what does this c code do? #include #include int main(int argc, char *argv[]) { FILE *in; int c; assert(argc == 2); in = fopen(argv[1], "r"); assert(in); while ((c = fgetc(in)) != EOF) { if (c == '\n') { putchar('$'); } putchar(c); } return 0; }

OpenStudy (anonymous):

One of the ways to figure out what a piece of code does is by splitting it into easier parts. You could split your example into three parts: 1) assert(argc == 2); in = fopen(argv[1], "r"); assert(in); 2) while ((c = fgetc(in)) != EOF) 3) if (c == '\n') { putchar('$'); } putchar(c); You'll need to figure out what happens in 1, when the loop in 2 will stop and what will be done each iteration of the loop (3).

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!