"Money" <sp*********@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
>I am doing things the right way or does it needs modification?
#include <stdio.h>
#define MS_DOS_EOF 26
#define MS_DOS_CR 13
int main(int argc, char *argv[])
{
int ch;
FILE *in, *out;
in = fopen(argv[1],"rb");
out = fopen(argv[2],"wb");
while (1)
{
ch = fgetc(in);
switch(ch)
{
case EOF:
case MS_DOS_EOF:
fclose(in);
fclose(out);
exit(0);
case MS_DOS_CR:
break;
default:
fputc(ch, out);
break;
}
}
return 0;
}
Comments:
a)If you're running this on a Unix system, look up the dos2unix utility --
already exists and seems to work fine.
b)Given that the standard Windows line termination is 13-10 and Unix is 10,
your program should work.
c)You might want to look carefully at the last-line-of-the-file cases. I'm
not sure of Unix convention--whether that gets a terminator or not, and
whether this convention is the same for Windows.