Tech ARP Forums

Go Back   Tech ARP Forums > Software Discussion > General Software
Register
FAQ Members List Calendar Arcade Mark Forums Read

Google Web www.techarp.com forums.techarp.com

General Software This is the forum for general discussions about software.

Reply
 
LinkBack Thread Tools
Old 12th Oct 2006, 06:26 AM   #1 (permalink)
Warming up
 
decypher's Avatar
 
Join Date: 30 Jul 2006
Location: A galaxy far, far away
Posts: 131
Reputation: 29
decypher is on a distinguished road
Rep Power: 3
Default Some noob array problem in C

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);
As for the -1 rule, I tried this right after the scanf line.

Code:
if(a==-1) {
break;
}
The thing is, when I run the program, everything worked fine except that I had to complete the line with three values to end the program. I had to type:
Quote:
-1 b c
where b and c are two random integers by the user.

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!
decypher is offline   Reply With Quote
SPONSOR

Old 12th Oct 2006, 09:30 AM   #2 (permalink)
I Lurrrve Panda Biscuit!
 
strawroot's Avatar
 
Join Date: 3 Jul 2006
Location: sitting next to da almighty boss
Posts: 2,318
Reputation: 1964
strawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant futurestrawroot has a brilliant future
Rep Power: 24
Default



i would really like to help... but.....
__________________
You know you're really trailer trash when... You think Genitalia is an Italian airline.
strawroot is offline   Reply With Quote
Old 12th Oct 2006, 10:07 AM   #3 (permalink)
ARP Webmaster
 
peaz's Avatar
 
Join Date: 13 Oct 2002
Location: http://atpeaz.placidthoughts.com/
Posts: 8,500
Reputation: 1633
peaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant futurepeaz has a brilliant future
Rep Power: 31
Default

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.
peaz is offline   Reply With Quote
Old 12th Oct 2006, 04:02 PM   #4 (permalink)
Warming up
 
decypher's Avatar
 
Join Date: 30 Jul 2006
Location: A galaxy far, far away
Posts: 131
Reputation: 29
decypher is on a distinguished road
Rep Power: 3
Default

A parser. String Tokenizer and casting? God damn. If this were Java I wouldn't need to go on my knees. Will try that idea, thanks peaz.
decypher is offline   Reply With Quote
Old 12th Oct 2006, 04:23 PM   #5 (permalink)
Active
 
djspinnet's Avatar
 
Join Date: 3 Jun 2005
Posts: 591
Reputation: 583
djspinnet is a name known to alldjspinnet is a name known to alldjspinnet is a name known to alldjspinnet is a name known to alldjspinnet is a name known to alldjspinnet is a name known to all
Rep Power: 9
Default

Quote:
Originally Posted by decypher View Post
A parser. String Tokenizer and casting? God damn. If this were Java I wouldn't need to go on my knees. Will try that idea, thanks peaz.
casting?

oh, casting is easy peasy. ever heard of atoi?
__________________
Jinny Wong
djspinnet.org
djspinnet is offline   Reply With Quote
Old 12th Oct 2006, 06:52 PM   #6 (permalink)
Warming up
 
decypher's Avatar
 
Join Date: 30 Jul 2006
Location: A galaxy far, far away
Posts: 131
Reputation: 29
decypher is on a distinguished road
Rep Power: 3
Default

oh ya atoi. adui. i threw away C when I studied Java.

gdmit.
decypher is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +8. The time now is 02:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 1998-2007 Tech ARP. All rights reserved.