![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2004
Posts: 18
Rep Power: 0
![]() |
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++;
* *}
}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 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2004
Posts: 18
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#4 |
|
Expert Programmer
|
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 <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|