Re: going through a string / char array and putting the bits in other variables
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 03/13/04
- Next message: DangerD321: "Re: going through a string / char array and putting the bits in other variables"
- Previous message: Victor Bazarov: "Re: Alternative to GetTickCount()"
- In reply to: DangerD321: "going through a string / char array and putting the bits in other variables"
- Next in thread: DangerD321: "Re: going through a string / char array and putting the bits in other variables"
- Reply: DangerD321: "Re: going through a string / char array and putting the bits in other variables"
- Reply: Old Wolf: "Re: going through a string / char array and putting the bits in other variables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 13 Mar 2004 21:19:06 GMT
"DangerD321" <dangerd321@aol.com> wrote...
> im trying to create a function which takes one line of input, either as a
> string or character array, and then reads through the string and takes
each
> word and stores it in other strings or characters, so say the line of
input
> was:
>
> Dean Steven 02/14/67
>
> and i would have a variable for first name, surname and dob set up. There
are
> more varialbes and stuff but Im tryin to do it myself I just don't know
where
> to look.
Have you tried a C++ book? If yes, which book? If not, why?
>I used just simpley if(aLine[counter] != ' ') to keep reading until a
> space but this isn't very efficient really
How do you know? Have you timed it versus some other method?
> and i was wodnering if there were
> just functions to do this sort of thing,
Yes, but essentially they just do that 'if(.. != ' ')' behind the scenes.
Take a look at 'strchr' for character arrays and 'find' for std::string.
> because some inputs like DOB will not
> always be there and i need to check. Also, it is not known how many spaces
are
> between each word.
Then you just skip them all. For std::string take a look at member
function find_first_not_of. For an array, just enumerate until you
find that it's not a space.
>
> I hope ive outlined the problem correctly, and thanks for any help,
Well, give it a shot (even if it's "inefficient"). There is a saying
among [experienced] programmers: first make it work, THEN make it fast.
Victor
- Next message: DangerD321: "Re: going through a string / char array and putting the bits in other variables"
- Previous message: Victor Bazarov: "Re: Alternative to GetTickCount()"
- In reply to: DangerD321: "going through a string / char array and putting the bits in other variables"
- Next in thread: DangerD321: "Re: going through a string / char array and putting the bits in other variables"
- Reply: DangerD321: "Re: going through a string / char array and putting the bits in other variables"
- Reply: Old Wolf: "Re: going through a string / char array and putting the bits in other variables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|