The Mother Board

Motherboards.org forums. Free tech support, motherboard ID, and more.
It is currently Fri Sep 21, 2018 11:57 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: C++ basic string input
PostPosted: Fri Jun 24, 2005 8:28 am 
Offline
Black Belt
Black Belt

Joined: Sun Jun 29, 2003 3:58 pm
Posts: 615
Location: South Africa, Cape Town
hello, im trying to get a very basic cosole app to do things right, but now suddenly it doesn't seem so simple, plz help :(

I simply need to read text into a string variable of which the length should be at least 6 and max 90.

If I use getLine() from the string library I will only be able to determine the length after having entered the text. I would like to do so during the input. I know this sounds simple, but... id appreciate some help. thanks :oops:

_________________
-dve83- Folding for 33258
Gigabyte GA-MA69VM-S2,AMD Athlon X2 5200+, 6GB DDR2-800, Seagate 250GB 7200 RPM, Western Digital 1TB 7200RPM,
460W Coolermaster PSU, Windows 7

"Perhaps it's not paranoia. Perhaps it's just finesse." - dve83


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 31, 2005 7:34 am 
Offline
Green Belt
Green Belt

Joined: Thu Jun 27, 2002 8:11 pm
Posts: 222
It sounds possible by somehow reading a character at a time and storing them in an array of characters, but I'm having trouble grasping why you would want to do this. Surely its easier to read in the string, validate its the right length and then either request it to be entered again (if its the wrong length) or move on to the next procedure. :-k


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 31, 2005 8:51 am 
Offline
Black Belt
Black Belt

Joined: Sun Jun 29, 2003 3:58 pm
Posts: 615
Location: South Africa, Cape Town
yes, it is indeed easier to it that way, and eventually I decided to go with it, but: its not what i wanted to do. I was looking to verify each character as it was entered OR at least verify the length of the string while it was being entered. I feel it would irritate and end user enormously if he was to re-enter the complete sentence each time it was too long.

_________________
-dve83- Folding for 33258
Gigabyte GA-MA69VM-S2,AMD Athlon X2 5200+, 6GB DDR2-800, Seagate 250GB 7200 RPM, Western Digital 1TB 7200RPM,
460W Coolermaster PSU, Windows 7

"Perhaps it's not paranoia. Perhaps it's just finesse." - dve83


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 31, 2005 9:47 am 
Offline
Green Belt
Green Belt

Joined: Thu Jun 27, 2002 8:11 pm
Posts: 222
dve83 wrote:
yes, it is indeed easier to it that way, and eventually I decided to go with it, but: its not what i wanted to do. I was looking to verify each character as it was entered OR at least verify the length of the string while it was being entered. I feel it would irritate and end user enormously if he was to re-enter the complete sentence each time it was too long.


Then the character array may have worked. My C is a bit rusty thesdays but I think its possible to read in a character at a time, store it in an array, validate it and then either request that character to be overwritten in the array or request the next character.

Here is some pseudo code as my C is not fresh in my mind:

int count = 0;
characterArray[90]

while(count<90)
{
characterArray[count] = getCharacter();

if(characterArray[count] != toWhatYouWantItToBE)
{
count = count --;
}
else
{
count++;
}
}


something like that. (very roughly and missing a few things like first time through the loop and controlling user input)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 31, 2005 10:02 pm 
Offline
Black Belt
Black Belt

Joined: Sun Jun 29, 2003 3:58 pm
Posts: 615
Location: South Africa, Cape Town
hey and thanks for the reply. yip, a char array seems best. if you have any idea how to do it with a string type variable though, lemme know. Im still wondering wether its possible. I could find no method / function returning the length of a string.

again, thanks for the reply&code. :)

_________________
-dve83- Folding for 33258
Gigabyte GA-MA69VM-S2,AMD Athlon X2 5200+, 6GB DDR2-800, Seagate 250GB 7200 RPM, Western Digital 1TB 7200RPM,
460W Coolermaster PSU, Windows 7

"Perhaps it's not paranoia. Perhaps it's just finesse." - dve83


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group