为什么scanf函数要求额外的输入?

时间:2015-03-02 21:09:15

标签: c

**#include <stdio.h>  
#define SIZE 3  
void scanA(int array[SIZE][SIZE]);  // prototyping
int main()  
{  
    int myarray[SIZE][SIZE];  
    int i,j;    

    printf("Please enter the array: \n");  
    scanArray(myarray);  
    for(i=0; i<SIZE; i++)  
        for(j=0; j<SIZE; j++)  
        {  
            printf("%c",myarray[i][j]);         
        }  
    printf("\n");  
    return 0;  
}  
void scanA(int array[SIZE][SIZE])  // function defintion
{  
    int i;  
    int j;  
    for(i=0; i<SIZE; i++)       // looping to scan
        for(j=0; j<SIZE; j++)  
        {  
            scanf("%c\n ",&array[i][j]); 
        }  
}**  

// scanA函数中的scanf要求10个字符,尽管它循环了9次     我想知道原因和解决方案。

1 个答案:

答案 0 :(得分:1)

尝试在%c之前放置一个空格(仅当您读取字符时),因为有时scanf将输入作为字符读取。 (我对此并不完全确定,但对我来说这个解决方案有效)

对不起我的英语,这不是我的主要语言:(