Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Having trouble with altering line of input.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Reality Check




PostPosted: Tue Feb 06, 2007 7:11 pm   Post subject: Having trouble with altering line of input.

So I have a program that starts off with a line of input. Basically the first integer in the line tells me how many more integers there will be. So if the first integer is an 11 then I will have 22 more integers to come each representing something. If its 10 then I will have 20 more integers. Now here is where I have trouble. Once the first integer has been entered, the teacher will not separate the other integers by pressing enter and then typing them, she will simply press space and continue on to type the needed integers. So a line may look like this:

11 2 1 3 5 1 8 2 1 8 2 1 8 3 8 1 2 3 8 2 4 1

So the first number is an 11 and so there are 22 numbers to follow. My question is, how do I know what the first integer is if my teacher simply presses space right after and gives me no chance of checking? My thought was to use getch and simply get the first integer, and then get the rest but then if she puts something 2 digits then it won't work. My way only works with one digit. Thanks for the help.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Tue Feb 06, 2007 7:49 pm   Post subject: Re: Having trouble with altering line of input.

parse the string after getting input and look for the first space. If the first character is a space, then do whatever you would do about it.
NikG




PostPosted: Tue Feb 06, 2007 7:53 pm   Post subject: RE:Having trouble with altering line of input.

Just get the whole line as a string (get varname:*)

Then, depending on what you need to do with those numbers, use the index function to separate them.

Edit: looks like you beat me to it Freakman.
Reality Check




PostPosted: Tue Feb 06, 2007 8:01 pm   Post subject: Re: Having trouble with altering line of input.

Thanks a lot both of you, that fixes things. Although I do need them as integers I can always convert them.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: