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!

More simple newbie questions......

Status
Not open for further replies.

Callahan

Technical User
Nov 21, 2001
174
0
0
GB
Ok, I've decided, programming is not for me, but I need to get this assignment finished so I'm putting it to you guys. Simple(!?) setup. The user enters a string of text in the following format John Doe*123 Baker Street*SomeCity*RG12 2AP. Now, the idea is that once the code is entered, the * will break the string down onto seperate lines. I managed to design the program to stop at the first * but now I'm stuck as to how to get it to read in the next part. My code is attached to give you some idea.

Thanks for any suggestions.

{
AnsiString Line;
int Index;
Line = ReadStringPr("Enter a non-empty line of text: ");
//insist on a non-empty line
while (Line == "")
Line = ReadStringPr("Please enter a non-empty line: ");
Index = 1;
while ((Index <= Length(Line)) && (Line[Index] == '*'))
Index = Index + 1;
if (Index <= Length(Line))
while ((Index <= Length(Line)) && (Line[Index] != '*'))
{
WriteChar(Line[Index]);
Index = Index + 1;
}
else WriteStringCr(&quot;You have entered a line without input.&quot;);

getchar();
return 0;
 
first, most implementations of a string are zero-based, so the condition should be (index<length), but I have never seen your style of programming before anyway, so its up to you to figure that one out.

second, you have a while loop with a condition that is identical to that of the if-statement directly above it.

I'm sorry, but that is all I could pick out of there with the time I have.

Hope this helps,
CINC
 
CINC,
[tab]AnsiString is 1 based. It is based on a Pascal string.

Callahan,
[tab]In addition to CINC's comment, AnsiString has a length method that is called like Line.Length(). James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top