^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here's a simple filter-type program.
#include <stdio.h>
int main(void) {
int cr = '\r'; /* the code for carriage return */
int c;
while ((c = getchar()) != EOF) {
if (c != cr) {
putchar(c);
}
}
return 0;
}
Simply redirect stdin from the file you want to remove carriage
returns from and redirect stdout to the new file.
Had you engaged your brain, you'd have realised that your filter is
useless for its intended purpose: stdin being a text stream, it won't
see any CR character that is part of a CR+LF pair: such pairs are simply
mapped to a '\n' character, when read from a text stream on a Windows
platform. Furthermore, when you output a '\n' character, the C runtime
system will turn it into a CR+LF pair.
Of course, your program would work on a Unix system, but the OP wants
to perform the conversion on the Windows side. The solution is
incredibly simple, assuming that argv[1] contains the input file name and
argv[2] the output file name. All error checking deliberately omitted:
int c;
FILE *in = fopen(argv[1], "r"), *out = fopen(argv[2], "wb");
while ((c = getc(in)) != EOF) putc(c, out);
Any CR that is part of a CR+LF pair will be automatically removed by the
C runtime system, because the input file is opened in text mode. The
opposite operation is not going to happen, because the output file is
opened in binary mode.
And you probably don't want to filter any CR that is not part of a CR+LF
pair...
As a last remark, if the file is sent using the FTP protocol, the
conversion will be automatically performed, if the transfer is made in
text mode.
Dan