W
Wondiws
Hi,
I have the following code, which is supposed to open a file where 0a (hex)
is used to mark a newline, and change this into 0d0a. But it places two 0d's
before every 0a.
Could somebody tell me what's wrong with this code?
/* newyork.c */
#include <stdio.h>
#define LF 10 /* character to find */
#define CR 13 /* character to place */
int main(int argc, char *argv[])
{ if (argc != 3)
{ printf("newyork <source> <target>");
return 0;
}
FILE *source, *target;
char ch;
source = fopen(argv[1], "r");
target = fopen(argv[2], "w");
while ((ch = fgetc(source)) != EOF)
{ if (ch == LF)
fprintf(target, "%c", CR);
fprintf(target, "%c", ch);
}
fclose(source);
fclose(target);
}
I have the following code, which is supposed to open a file where 0a (hex)
is used to mark a newline, and change this into 0d0a. But it places two 0d's
before every 0a.
Could somebody tell me what's wrong with this code?
/* newyork.c */
#include <stdio.h>
#define LF 10 /* character to find */
#define CR 13 /* character to place */
int main(int argc, char *argv[])
{ if (argc != 3)
{ printf("newyork <source> <target>");
return 0;
}
FILE *source, *target;
char ch;
source = fopen(argv[1], "r");
target = fopen(argv[2], "w");
while ((ch = fgetc(source)) != EOF)
{ if (ch == LF)
fprintf(target, "%c", CR);
fprintf(target, "%c", ch);
}
fclose(source);
fclose(target);
}