Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFile problems 1

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
This seems simple enough...I've done it plenty of times, but not using the CFile class. I've got a text file open and after I write a string of text to it, I want to insert a carriage return....again, seems simple enough...here is my code.

CFile Testfile ("C:\\testfile.txt", CFile:modeCreate | CFile::modeReadWrite)

Testfile.Write("testing\n", lstrlen("testing\n"));

That's what I have...I've tried all sorts of combinations, but I can't get the stupid carriage return to work properly. When I open the file up in Wordpad, it looks fine...but with notepad it doesn't work. What do I need to append to the end of my text strings to get it to recognize a carriage return in notepad? I just don't understand how wordpad can see it and notepad can't. BTW, I've tried \r, \n, \013, and char(13). It just shows a funky lookin character at the end of my sentence instead of doing a carriage return. Can someone please explain this weird anomality please? Thanks in advance!

Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
 
Try this

char carriage_return[2];
carriage_return[0] = 13;
carriage_return[1] = 10;

CFile Testfile("C:\\testfile.txt",CFile::modeCreate | CFile::modeReadWrite);

Testfile.Write("testing", lstrlen("testing"));
Testfile.Write(carriage_return,2);

This should take care of it :)

Matt

 
Hey dude, it worked like a charm. Thanks so much for your response!

Niky Williams
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top