Why scanf doesn't ask every turn

35 Views Asked by At

Explain me please why scanf doesn't ask Name 3 times? How to change code to achieve it?

#include <stdio.h>
int main(void)
{
    int i=0;
    while ( i < 3 ) {
        char name[10];
        printf("Enter your name: ");
        scanf("%[^\n]", name);

        printf("Name: %s \n",name);
        i++;
    }
    return 0;
}
./a.out
Enter your name: D
Name: D 
Enter your name: Name: D 
Enter your name: Name: D 
0

There are 0 best solutions below