Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > DOS text file to unix file

Reply
Thread Tools

DOS text file to unix file

 
 
Money
Guest
Posts: n/a
 
      11-23-2006
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;
}

 
Reply With Quote
 
 
 
 
David T. Ashley
Guest
Posts: n/a
 
      11-23-2006
"Money" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.



 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      11-23-2006
David T. Ashley wrote:

<snip>

> a)If you're running this on a Unix system, look up the dos2unix utility --
> already exists and seems to work fine.


the version I used annoyingly modified the file protection.


--
Nick Keighley

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert UNIX formated text files to DOS formated? walterbyrd Python 13 05-13-2009 02:32 PM
Reading Mac / Unix / DOS text files January Weiner Perl Misc 23 02-27-2006 08:25 AM
Dos vs Unix style text files Dave Moore C++ 8 02-12-2005 04:01 PM
Pickled text file causing ValueError (dos/unix issue) Aki Niimura Python 12 01-15-2005 04:05 PM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM



Advertisments