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;
}
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
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).