I'm trying to write a data text with c but something is wrong with process order. Loop repeats itself before complete. It have to 'yes or no' but it prints 'go' after ask and later scanf process. What is wrong in that code?
#include <stdio.h>
int main(){
FILE *potr;
char go = 'e',name[20],sname[20];
int age;
potr = fopen("example.txt","w");
if(potr == NULL) printf("File cannot open");
while(go != 'n'){
printf("go\n");
scanf("%s %s %d",name,sname,&age);
fprintf(potr,"%s %s %d",name,sname,age);
printf("\ny or n :");
scanf("%c",&go);
}
fclose(potr);
return 0;
}