473,396 Members | 1,838 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.

Is textpad really necessary in this regard !!!

How can we code to change a file format from UNIX to PC in C# ???
Aug 22 '07 #1
8 3707
kenobewan
4,871 Expert 4TB
Welcome to TSDN. Please provide more information. Thanks.
Aug 22 '07 #2
Plater
7,872 Expert 4TB
Generally the only difference between a UNIX-based text file and a windows-based text file is the use of the '\r' character.
Unix-based textfiles terminate lines with just a '\n' (line-feed)
While Windows-based use the "\r\n" combination (cariage return/line-feed)

So if you wanted to you could read in the file and replace the "\n" with "\r\n" and you should be able to read it normally.
Aug 22 '07 #3
TRScheel
638 Expert 512MB
Generally the only difference between a UNIX-based text file and a windows-based text file is the use of the '\r' character.
Unix-based textfiles terminate lines with just a '\n' (line-feed)
While Windows-based use the "\r\n" combination (cariage return/line-feed)

So if you wanted to you could read in the file and replace the "\n" with "\r\n" and you should be able to read it normally.
I have never had problems with text files that end in \n while reading them in Windows.
Aug 22 '07 #4
Plater
7,872 Expert 4TB
I have never had problems with text files that end in \n while reading them in Windows.
Well, I believe notepad doesn't view them correctly.
Also, some text editors (such as ultraedit, as I use) detect it and I have it set to ask me if i want to view it as a dos-style or unix-style.
Aug 22 '07 #5
TRScheel
638 Expert 512MB
Well, I believe notepad doesn't view them correctly.
Also, some text editors (such as ultraedit, as I use) detect it and I have it set to ask me if i want to view it as a dos-style or unix-style.
My notepad > your notepad?

Hehe, on a serious note, I have never noticed a problem viewing them. Something like:

Expand|Select|Wrap|Line Numbers
  1. StreamWriter SWriter = new StreamWriter("MyText.txt");
  2. SWriter.Write("Test\nTest\nTest");
  3. SWriter.Close();
  4.  
Will produce a readable txt file for me.
Aug 22 '07 #6
Plater
7,872 Expert 4TB
Hehe, maybe they've upgraded themselves.
But for generic formating:
DOS Format - CRLF
UNIX Format - LF
MAC Format - CR
(Everyone's gotta be different)

As to the original question, maybe the difference in line terminators isn't the actual problem?
Aug 22 '07 #7
QUOTE=TRScheel]My notepad > your notepad?

Hehe, on a serious note, I have never noticed a problem viewing them. Something like:

Expand|Select|Wrap|Line Numbers
  1. StreamWriter SWriter = new StreamWriter("MyText.txt");
  2. SWriter.Write("Test\nTest\nTest");
  3. SWriter.Close();
  4.  
Will produce a readable txt file for me.[/quote]

Although your program writes seemingly only a \n from a c program, the binary file produced actually contains carriage return + line feed (x'0d0a'), on a windows platform. You can see this with a binary editor (I use spf/pc with profile 'exe').
Also, if you open an ordinary text file in c with binary mode fopen(<filename>, "rb") and read it then with fread -function , you can see x'0d0a' in the buffer.

Moreover, after "r" -mode fopen(<filename>, "r"),
fread suppresses all 2-byte CRLF (0d0a) to 1-byte LF (0a).
so you can only see x'0a' in buffer.

Also, if you ask for a file length in a c-program with a
fseek(fileptr, 0, SEEK_END); byteCount = ftell(fileptr);
the bytecount is the real length of the file, i.e. including
x'0d0a', not x'0a' (\n) only.

On a unix it is only x'0a' line separator in a text file. If you transfer a file from unix having x'0a' line separators, at least my notepad (5.1 sp2) can't show them properly, instead you see one long stream with non-printable byte where the line separator should be. But wordpad can read it, and when you save it, you have
x'0d0a' so it adds the 'x0d'.
Aug 25 '07 #8
TRScheel
638 Expert 512MB
My notepad > your notepad?

Hehe, on a serious note, I have never noticed a problem viewing them. Something like:

Expand|Select|Wrap|Line Numbers
  1. StreamWriter SWriter = new StreamWriter("MyText.txt");
  2. SWriter.Write("Test\nTest\nTest");
  3. SWriter.Close();
  4.  
Will produce a readable txt file for me.
Although your program writes seemingly only a \n from a c program, the binary file produced actually contains carriage return + line feed (x'0d0a'), on a windows platform. You can see this with a binary editor (I use spf/pc with profile 'exe').
Also, if you open an ordinary text file in c with binary mode fopen(<filename>, "rb") and read it then with fread -function , you can see x'0d0a' in the buffer.

Moreover, after "r" -mode fopen(<filename>, "r"),
fread suppresses all 2-byte CRLF (0d0a) to 1-byte LF (0a).
so you can only see x'0a' in buffer.

Also, if you ask for a file length in a c-program with a
fseek(fileptr, 0, SEEK_END); byteCount = ftell(fileptr);
the bytecount is the real length of the file, i.e. including
x'0d0a', not x'0a' (\n) only.

On a unix it is only x'0a' line separator in a text file. If you transfer a file from unix having x'0a' line separators, at least my notepad (5.1 sp2) can't show them properly, instead you see one long stream with non-printable byte where the line separator should be. But wordpad can read it, and when you save it, you have
x'0d0a' so it adds the 'x0d'.
I just checked that, and it seems you are right. I had never noticed that.
Aug 27 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: GianGuz | last post by:
Everyone knows about the complex and cpu-expensive procedures taken by dynamic_cast to find the right function call in a virtual classes hierarchy. The question I would to rise is when...
12
by: Jack | last post by:
Hi, Is it recommended to use the var keyword when declaring a variable? IE lets me create a variable with var, then create the same one again with no problem. Also it lets me create a...
22
by: What Rhyme is it? | last post by:
....for <some poets> to show their stupidity about technical issues that they don't have a shred of a clue about. I really have to wonder. With that, I must wash my imaginary cat.
5
by: crescent_au | last post by:
Hi all, I've been using PHP for a while now but I haven't actually used PEAR. I have just read half a chapter in a book, it sounds alright but haven't actually used it. I was just wondering, is...
6
by: Thierry Lam | last post by:
I was reading the book AJAX in action and it mentions using ORM tools such as PEAR, EZPDO or Metastorage. The ORM is supposed to facilitate data retrieval. Is everyone out there using one of those...
18
by: Earl Anderson | last post by:
First, I feel somewhat embarrassed and apologetic that this post is lengthy, but in an effort to furnish sufficient information (as opposed to too little information) to you, I wanted to supply all...
7
by: Jim Langston | last post by:
I'm working on a program, and at one time I find it necessary to load classes into a map. Now, these classes don't have default constructors, so I can't retrieve them using MyMap. So I wound...
16
by: Bill Cunningham | last post by:
Is it really necessary to check the return type (int) or fclose ? fopen I can understand but what about using fflsuh(fp); /* fopen's pointer */ fclose(fp); Would that take care of any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.