When I read in a file and then output to a new file, the output is garbled, and I am trying to figure out why.
I am trying to run the following code
#include<stdio.h>
#include<stdlib.h>
int main(int argc ,char *argv[])
{
int c;
FILE *of;
FILE *f;
of=fopen(argv[2],"w");
f=fopen(argv[1],"r");
while(c=getc(f)!=EOF)
putc(c,of);
fclose(of);
fclose(f);
return 0;
}
But when I run it as follows
$./a.out temp new
where temp is an existing file whose contents are:
this is a temp file and new doesn’t exist before running the program
But now when I cat the contents of new it is all messed up why it is so?
needs parentheses,
the precedence of
!=is higher than that of the assignment=.