So, i have an input file that looks like this:
line1
line2
and i want to write the output file like this:
line1,line2
And for now the output is with newline like this:
line1,
line2,
If I replace \r with \n the output will be like the input.
Here is my code:
int main()
{
/* Pointer to the file */
FILE *fp1;
FILE *fp2;
/* Character variable to read the content of file */
char c;
/* Opening a file in r mode*/
fp1= fopen ("Newfile.txt", "r");
fp2 = fopen ("result.txt","w");
/* Infinite loop –I have used break to come out of the loop*/
while(1)
{
c = fgetc(fp1);
if(c==EOF)
break;
else if(c=='\r')
fprintf(fp2,",");
else
fprintf(fp2,"%c", c);
}
fclose(fp1);
fclose(fp2);
return 0;
}