Here's the code I wrote:
Code:
#include<stdio.h>
#include<conio.h>
void initialize(int array[9][9])
{
int i = 0, j = 0;
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9; j++)
{
array[i][j] = 0;
}
}
}
void display(int array[9][9])
{
int i = 0, j = 0;
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9; j++)
{
printf("%d ", array[i][j]);
}
printf("\n");
}
}
int main(void)
{
int array[9][9];
char c;
initialize(array);
display(array);
printf("Enter the array elements: \n\n");
while(1)
{
printf("\nWant to enter array element? ");
scanf("%c", &c);
if(c == 'y')
{
printf("Accepted");
}
else
{
printf("Bye bye");
break;
}
}
getch();
return 0;
}
The scanf function works only once, it only scans the character once.
On the second iteration, the scanf function is skipped and the loop exits.
Am I do anything wrong?
Thanks in advance.