473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DOS text file to unix file

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;
}

Nov 23 '06 #1
2 1498
"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.

Nov 23 '06 #2
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

Nov 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Sami Viitanen | last post by:
Hello, How can I check if a file is binary or text? There was some easy way but I forgot it.. Thanks in adv.
1
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
4
by: kalio80 | last post by:
Hi everyone I posted an enquiry earlier about using c++ code to convert text files between linux & widows. I ended up with this code: #include <iostream> #include <fstream> using namespace...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
3
by: comp.lang.php | last post by:
PHP 4.3.8 with UNIX with option --with-magic_mime echo mime_content_type('/images/myimage.png'); // RETURNS "text/plain" PHP 4.3.11 with UNIX with option --with-magic_mime echo...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
10
by: Kenneth Brody | last post by:
I recently ran into an "issue" related to text files and ftell/fseek, and I'd like to know if it's a bug, or simply an annoying, but still conforming, implementation. The platform is Windows,...
7
by: programming | last post by:
Hi all, i have been having trouble with a login script that works on my windows machine, however when i upload it to the Unix server through VPN, the same script won't work! It won't parse...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
2
by: sethridge1991 | last post by:
Hi Everyone, I am trying to send a XML file via SFTP staying completely in UNIX. The data in the file will vary everytime I create and send it. This is not a simple address book dump. This...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.