EntropySink

Technical & Scientific => Software => Topic started by: Micko on April 28, 2005, 06:03:40 PM

Title: question about files
Post by: Micko on April 28, 2005, 06:03:40 PM
When you open file stdio.h (in attachment) you'll se (at least I see) that is very hard to read wth some weird symbols etc. I made following steps:
Select All -> Copy and Past to MS Word(here's becoming OK) ->Select all -> Copy and Paste to new file stdio1.h.
Now stdio1.h is like any other normal text file. Now I assume this is because of different file system (maybe I'm not using appropriate expressino) in Linux and Windows. Is this correct?
Why the look is different? I read something about Linux file formatting, but I was hoping someone here will explain it to me.
Thanks

- Micko
Title: question about files
Post by: Mike on April 28, 2005, 06:15:19 PM
Linux uses one character for new lines "\n" (line feed).  MS uses two characters for new lines "\r\n" (carriage return and line feed)

So MS has a problem with it because it expects both characters but only gets one
Title: question about files
Post by: Micko on April 28, 2005, 06:35:01 PM
That is why stdio1.h is a little bigger.
So basically when windows file manager (or what?) find only \n it replace it with some strage marklike a little rectangle. OK
I use win xp and when I use something like this in C:
Code: [Select]

fprintf(fp, "Test\n");


Windows will write Test\r\n in file. Am I right ?
Title: question about files
Post by: sand_man on April 29, 2005, 01:18:59 AM
wouldn't it be
\n = \f\r
Title: question about files
Post by: Micko on April 29, 2005, 08:01:26 AM
Now, I lost you. What is \f ?
Title: question about files
Post by: Ken Fitlike on April 29, 2005, 08:12:01 AM
No idea.

Stick to what Mike's said as that's the way it is.

Download SciTE (http://www.scintilla.org/SciTE.html) - it can display and convert between linux and window line break formats, as well as being a very good text/code editor that works on both operating systems so you can use it to view any text file (including that stdio.h) as a 'normal' text file regardless of its line break characteristics.
Title: question about files
Post by: Major_Small on April 29, 2005, 09:57:42 AM
Quote from: Ken Fitlike
No idea.

Stick to what Mike's said as that's the way it is.

Download SciTE (http://www.scintilla.org/SciTE.html) - it can display and convert between linux and window line break formats, as well as being a very good text/code editor that works on both operating systems so you can use it to view any text file (including that stdio.h) as a 'normal' text file regardless of its line break characteristics.

/f is a form-feed character... used in old-school printing. to push the rest of the page out of the printer after you were done printing on it.
Title: question about files
Post by: Govtcheez on April 29, 2005, 10:10:10 AM
Shouldn't it be a line feed and a carriage return, though?
Title: question about files
Post by: Major_Small on April 29, 2005, 10:29:54 AM
Quote from: Govtcheez
Shouldn't it be a line feed and a carriage return, though?

did it really matter back in the day? MS just chose an order and went with it :D
Title: question about files
Post by: Micko on April 29, 2005, 10:37:00 AM
Thanks guys
Title: question about files
Post by: Mike on April 29, 2005, 10:54:44 AM
It's been a while since I've actually looked so I can't remember if its 13 10 or 10 13.  I know its \r\n when doing windows stuff.
I do think my typewriters did it newline carriage return though.
Title: question about files
Post by: Govtcheez on April 29, 2005, 11:20:03 AM
Quote from: Major_Small
did it really matter back in the day? MS just chose an order and went with it :D

I didn't mean the order was important (it's not).  I meant that it was important that it was a line feed instead of a form feed, unless you want one line per page.
Title: question about files
Post by: Major_Small on April 29, 2005, 11:28:20 AM
Quote from: Govtcheez
I didn't mean the order was important (it's not).  I meant that it was important that it was a line feed instead of a form feed, unless you want one line per page.

well, yeah... I think \n kinda-sorta takes the place of a linefeed... maybe?  :dunno:
Title: question about files
Post by: Govtcheez on April 29, 2005, 11:50:58 AM
We're going in circles :(

All I'm saying is that sandman's response of \f\r is going to be wrong; it should be \l\r or \r\l.
Title: question about files
Post by: Major_Small on April 29, 2005, 12:02:40 PM
Quote from: Govtcheez
We're going in circles :(

All I'm saying is that sandman's response of \f\r is going to be wrong; it should be \l\r or \r\l.

oh, well I kinda figured that was a given :(
Title: question about files
Post by: Govtcheez on April 29, 2005, 12:03:14 PM
OK, I'm going away now because I'm confusing everyone.
Title: question about files
Post by: Micko on May 01, 2005, 10:02:43 AM
Well here's what I found:

Quote

Q:
What is the difference between \n and \r\n ? Should I be concerned about the differences ?
What types of characters indicate a new line ?

A:

Background

There are a few characters which can indicate a new line. The usual ones are these two:

"\n" or 0x0A (10 in decimal)

This character is called "Line Feed" (LF).
"\r" or 0x0D (13 in decimal)

This one is called "Carriage return" (CR)
Different Operating Systems handle newlines in a different way. Here is a short list of the most common ones:
DOS and Windows

They expect a newline to be the combination of two characters, namely "\r\n" (or 13 followed by 10).
Unix (and hence Linux as well)

Unix uses a single "\n" to indicate a new line.
Mac

Macs use a single "\r".
This difference gives rise to a number of problems. For example, a file created under Unix (so with newlines as a single LF) will not open correctly under Window's Notepad. Any Windows program that expects newlines to be CRLF will not work correctly with these files.

Title: question about files
Post by: [stealth] on May 01, 2005, 10:09:40 AM
Off topic/ Hey Micko, nice to have ya aboard! /Off topic