-2
**#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]); 
        }  
}**  

//The scanf in the scanA function asks for 10 chars although it is looped 9 times I want to know the reason and a solution.

pahan
  • 567
  • 1
  • 8
  • 22

1 Answers1

1

Try to put a blank space before the %c (only when you read a char), cause sometimes scanf reads the enter as a char. (I'm not totally sure about it, but with me this solution works)

Sorry for my english, it isn't my main language :(

sentientmachine
  • 347
  • 3
  • 14
  • It worked. Thanks for your answer. But, is there a particular reason behind it? I want to know that. – pahan Mar 03 '15 at 03:36
  • You must add the blank space because when you enter the char and press enter scanf reads two chars:the char you insert and the enter – sentientmachine Mar 03 '15 at 07:23
  • @PahanMadusha here is another explanation. http://stackoverflow.com/questions/17079144/why-we-need-to-put-space-before-c – sentientmachine Mar 03 '15 at 14:14