Computing.Net > Forums > Programming > C++ help needed

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

C++ help needed

Reply to Message Icon

Original Message
Name: Mercutio
Date: August 9, 2002 at 04:52:02 Pacific
Subject: C++ help needed
Comment:

Hi,

I am studying C++ atm but I'm a tad stuck on a problem I have:

I am doing a project which requires me to take a strings of varying length from a text file, cut them up and perform various validation checks on them.

For example;

12436jimmylaboffablahblah

would have to be chopped into

12436 | jimmy la boffa | blah blah

I have the necessary structures to store the data, all the functions I need to perform the tests but I cannot for the life of me figure out how to take the string and chop it up into various pieces. :/

I have looked through all the books I have but I have had no luck in finding a potential solution.

I was experimenting with using commands such as :

fin.getline(temp, MAX); //gets the string
drec.number = temp[5];
drec.name = temp[20];
etc...

but I'm pretty sure that this is not correct. Any help would be greatly appreciated.

Thanks,

James


Report Offensive Message For Removal


Response Number 1
Name: cup
Date: August 9, 2002 at 09:34:26 Pacific
Reply: (edit)

Try this

struct Data
{
char number[5];
char name[13];
char etc[80]; // whatever the size is
} temp;

getline ((char*) &temp, sizeof (Data));

cout << temp.number << " | " << temp.name << " | " << endl;


Report Offensive Follow Up For Removal

Response Number 2
Name: hmm
Date: August 10, 2002 at 17:24:01 Pacific
Reply: (edit)

what are the validation checks? and what is the rule for determining the string? How will you know when one string ends and another begins? by size? or do you have a list of valid entries?


Report Offensive Follow Up For Removal

Response Number 3
Name: Gian Franco Alongi
Date: August 11, 2002 at 05:51:16 Pacific
Reply: (edit)


Once you get the rules of the splitting
it will be far more easier... =)


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software