Web Advertising - Online Advertising - Fast Loans - Servidores - 1-shoes-shopping.com

PDA

View Full Version : [C] scanf


Alhazred
Jul 12th 2004, 9:31 am
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?