| | |
The difference of '\n' in windows and linux.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
Is there anyway that you can convert the '\n' in windows which is 2bytes to the '\n' 1byte so that the linux could read it?
To do it in code, just set your output file mode to "binary". Doing so turns off the '\n' to "\r\n" translations, so when you write your file you get exactly what you write --single newline and all.
•
•
•
•
In addition, does the fread() function can use wchar_t* type as buffer?
However, there are usually functions to convert a binary string to a unicode string...
(I don't know what they are though.)
Hope this helps.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
converting ascii text files is trivial; you have a variety of tools. eg. tr, perl, awk, vi etc.in fact anything that can replace a cr-lf sequence with just a cr. eg.
you could also use a utility called tofrodos which is available on a number of systems (under different names like "todos", "fromdos", "dos2unix", "unix2dos" etc.)
http://kb.iu.edu/data/acux.html
http://www.thefreecountry.com/tofrodos/
if the files are in unicode, these simple techniques will not work. unicode has a variety of newlines: CR (000D), LF (000A), CRLF (000D,000A), NEL (0085), FF (000C), LS (2028), and PS (2029). for a perl hack see http://www.onlamp.com/pub/a/onlamp/2...es.html?page=3. it is easy in c++ to write a function that processes input character by character and does the necessary translations.
fread and fwrite are to i/o what memcpy is to memory. it reads or writes bytes into untyped memory (void*) without any formatting or interpretation. the stream should be opened in binary ("b") mode to prevent newline character translations by the underlying layers. for example,
using these functions correctly is difficult; mainly because they do not distinguish between end of file and error. use of feof and ferror is required to determine what has occurred.
awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt you could also use a utility called tofrodos which is available on a number of systems (under different names like "todos", "fromdos", "dos2unix", "unix2dos" etc.)
http://kb.iu.edu/data/acux.html
http://www.thefreecountry.com/tofrodos/
if the files are in unicode, these simple techniques will not work. unicode has a variety of newlines: CR (000D), LF (000A), CRLF (000D,000A), NEL (0085), FF (000C), LS (2028), and PS (2029). for a perl hack see http://www.onlamp.com/pub/a/onlamp/2...es.html?page=3. it is easy in c++ to write a function that processes input character by character and does the necessary translations.
fread and fwrite are to i/o what memcpy is to memory. it reads or writes bytes into untyped memory (void*) without any formatting or interpretation. the stream should be opened in binary ("b") mode to prevent newline character translations by the underlying layers. for example,
C++ Syntax (Toggle Plain Text)
int array[100] ; // to write an array (binary) into afile fwrite( array, sizeof(int), 100, file ); // to read the array (binary) from a file fread( array, sizeof(int), 100, file ); struct some_struct mystruct ; // write fwrite( &mystruct, sizeof(struct some_struct), 1, file ) ; // read fread( &mystruct, sizeof(struct some_struct), 1, file ) ;
![]() |
Similar Threads
- Why linux executable(a.out) doesnt run on windows(.exe) directly? (C)
- Windows to Linux Migration (Getting Started and Choosing a Distro)
- Windows vs Linux (IT Professionals' Lounge)
Other Threads in the C++ Forum
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






