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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get a newline

Status
Not open for further replies.

victorsk

Programmer
Jul 26, 2005
21
CA
Hello,

I am working on a small procedure and it's giving me a headache. I have a
file that consists exactly of the following info:
Name1/
Name2/
Name3/

I am trying to read each name into a string and display it in a lisbox.
Here is what I am doing:

TRY
{
pFile = new CFile(_T("C:\\Data\\SVG\\Web\\layers.txt"),
CFile::modeRead | CFile::shareDenyNone);
char pbuf [1000];
UINT nBytesRead = pFile->Read(pbuf, sizeof(pbuf));
int z = 0;
int i = 0;
int count = 0;
CString layer;
//GET THE DELIMITER NUMBER
while (z < 1000)
{
if (pbuf[z] == '/')
{
count++;
}
z++;
}
//GO THROUGH NUMBER OF DELIMITERS
//TO APPEND TO STRING
for (int u = 0; u < count; u++)
{
while (pbuf != '/')
{
layer += pbuf;
i++;
}
m_layer.AddString(layer);
}
}

What I keep getting in my ListBox is this:
Name1
Name1
Name1
Obviously the output is wrong and I think what is happening is that my index 'i' stops at the end of Name1 and then doesn't go to the next line so during next iterations I keep getting the same name Name1.

Could somebody please tell me how to move index to the newline please? I tried "/n" or "\n" (not sure which one) but this didn't work. Is there a way to move index to the newline in my code? Please, help.

Thank you,
Victor.

 
Hi Folks,

I think the class I am looking for is CStdioFile. I'll give that one a try.

Vic.
 
Victor,

You should clear your layer variable:

m_layer.AddString(layer);
layer = "";

If your box is just large enough to display "Name1" then you may not see that layer goes as follows:

Name1
Name1Name2
Name1Name2Name3

Hope this helps.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top