![]() |
| Register | |||||||
| General Software This is the forum for general discussions about software. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) | |
| Warming up Join Date: 30 Jul 2006 Location: A galaxy far, far away
Posts: 131
Reputation: 29 ![]() Rep Power: 3 | Anyone want to flex some C programming muscles? Do me a big favour by solving this problem. I need to write a program that accepts three values in one line. At the beginning, I thought a simple scanf with three integer inputs would do the trick. But no, the question had a twist to it: if the user inputted -1 as first (and only) value, the loop will break. Right now, I have this line. Code: scanf("%d %d %d", &a, &b, &c); Code: if(a==-1) {
break;
} Quote:
How do I code it so that the program will know to break the loop by reading only the first value and ignoring the subsequent values? Any help is appreciated. Thanks! | |
| | |
| SPONSOR |
| |
| | #2 (permalink) |
| I Lurrrve Panda Biscuit! Join Date: 3 Jul 2006 Location: sitting next to da almighty boss
Posts: 2,318
Reputation: 1964 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Rep Power: 24 | i would really like to help... but..... ![]()
__________________ You know you're really trailer trash when... You think Genitalia is an Italian airline. |
| | |
| | #3 (permalink) |
| ARP Webmaster Join Date: 13 Oct 2002 Location: http://atpeaz.placidthoughts.com/
Posts: 8,500
Reputation: 1633 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Rep Power: 31 | what you need to do is to create a routine then checks on each keystroke. every number is escaped by a 'space' that's how u can assign a number to the variable. the trick here is that you will be getting chars and thus you'll need to convert it to an integer once you've recieved the 'space' char. Repeat that 3 times using a for loop. and for the first loop, check if its a "-1" if so, then break the whole routine. Try and see if you get what I mean. if you still need help I'll write up part of the program for you. No fun if I gave u everything now. |
| | |
| | #5 (permalink) | |
| Active Join Date: 3 Jun 2005
Posts: 591
Reputation: 583 ![]() ![]() ![]() ![]() ![]() ![]() Rep Power: 9 | Quote:
oh, casting is easy peasy. ever heard of atoi? | |
| | |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ic7g - Serious System Crash Problem With Nero Problem - Is it Hardware ? | dthind | General Hardware | 12 | 15th Dec 2006 10:55 AM |
| problem with video playback.. | athlonxp | Graphics Cards & Displays | 5 | 6th Jan 2006 02:01 AM |