1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[C] scanf

Discussion in 'Programming' started by Alhazred, Jul 12, 2004.

  1. #1
    
    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++;
        }
    }
    
    Code (markup):
    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?
     
    Alhazred, Jul 12, 2004 IP