Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 12th, 2004, 12:33 PM   #1
Alhazred
Newbie
 
Join Date: Jul 2004
Posts: 18
Rep Power: 0 Alhazred is on a distinguished road
void PosizionaNavi(){
 * int Count = numeroNavi, nave = 1;
 * char c_col = ' ';
 * int raw = 0;

 * printf("Insert coordinates for ship %i.\n",numeroNavi);
 * while(Count>0){
 * * * *printf("Ship %u - Column: ",nave);
 * * * *scanf("%c",&c_col);
 * * * *printf(" * * raw: ");
 * * * *scanf("%d",&raw);
 * * * *printf("\n");
 * * * *while((c_col<'A'||c_col>'J')&&(raw<1||raw>10)){
       *printf("Invalid input, reinsert coordinates.\n");
       *printf("Ship %u - Column: ",nave);
       *scanf("%c",&c_col);
       *printf(" * * Raw: ");
 *      scanf("%d",&raw);
 *      printf("\n");
 * * * *}
 * * * *mArray[nave-1].colonna = c_col;
 * * * *mArray[nave-1].riga = raw;
 * * * *Count++;
 * * * *nave++;
 * *}
}
If I run this code, for the first coordinates there's no problem, but when I should insert the second, I can't insert the column.
I know it's due to the enter key press when I insert the raw before, but I don't know how to corrct this problem.
Could you help me?
__________________
<span style='color:blue'>Hayaki koto kaze no gotoku.</span> <span style='color:green'>Shizukanaru koto hayashi no gotoku.</span>
<span style='color:red'>Shinryakusuru koto hi no gotoku.</span> <span style='color:brown'>Ugokazaru koto yama no gotoku.</span>


My house in Rome: http://lacasa.altervista.org
Alhazred is offline   Reply With Quote
Old Jul 12th, 2004, 2:31 PM   #2
sarumont
Hobbyist Programmer
 
sarumont's Avatar
 
Join Date: Apr 2004
Location: /dev/urandom
Posts: 154
Rep Power: 5 sarumont is on a distinguished road
Send a message via ICQ to sarumont Send a message via AIM to sarumont Send a message via Yahoo to sarumont
Can you post the output when you run it? This may fix it (and you should do it anyway): put the command fflush(stdin); after each scanf statement. This will flush the STDIN stream of any extra characters. You can also use this to flush other streams such as sockets and filehandles.
__________________
"Time is an illusion. Lunchtime doubly so."
-the late, great Douglas Adams
sarumont is offline   Reply With Quote
Old Jul 13th, 2004, 3:55 AM   #3
Alhazred
Newbie
 
Join Date: Jul 2004
Posts: 18
Rep Power: 0 Alhazred is on a distinguished road
Thanks, now it works
__________________
<span style='color:blue'>Hayaki koto kaze no gotoku.</span> <span style='color:green'>Shizukanaru koto hayashi no gotoku.</span>
<span style='color:red'>Shinryakusuru koto hi no gotoku.</span> <span style='color:brown'>Ugokazaru koto yama no gotoku.</span>


My house in Rome: http://lacasa.altervista.org
Alhazred is offline   Reply With Quote
Old Jul 22nd, 2004, 1:17 AM   #4
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
The return when you press it enter the character '\n' into the character stream if I recall correctly, so if you do not flush the stream after each scanf you get the problem if that extra character being read next time you call that function.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC