Remove Carriage Returns from char* (C++) -


i have defined resource file in visual studio 2008 c++ project. problem after obtaining resource data lockresource method resulting char buffer contains carriage returns , line feeds original data contained line feeds. instance if original line contains:

00 0a fc 80 00 00 27 10 00 0a fc 80 00 00 27 10

the resulting char* contains carriage returns (0d):

00 0d 0a fc 80 00 00 27 10 00 0d 0a fc 80 00 00

i tried following code rid of them results in both carriage return , line feed removed:

for (int = 0; < sz; ++i) {     // ignore carriage returns     if (data[i] == '\n') continue;     // ... } 

how rid of carriage returns leave new line characters?

edit:

to make more specific. writing char buffer file:

std::ofstream outputfile(filename.c_str());  (int = 0; < sz; ++i) {     // ignore carriage returns     // if (data[i] == '\r') continue; leaves both cr , lf      // if (data[i] == 0x0d) continue; leaves both cr , lf     if (data[i]) == '\n') continue; //this removes both cr , lf     outputfile << data[i]; } 

when write '\n' text file converted 'end of line sequence'. in case looks '\r\n'. when read text file 'end of line sequence' converted single '\n' character. normal processing character should not affect (assuming open both read/write text files).

if not want '\n' converted 'end of line sequence' open file binary. when done no processing done on '\n' character.

std::ofstream outputfile(filename.c_str(), std::ios::binary);                                         // ^^^^^^^^^^^^^^^^ 

but note: file representation should not affect you. if open , read file text '\r\n' converted single '\n' character within application.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -