#define REGISTER (char *[5]) {"REGISTER NEW USER ACCOUNT", "Name:","User ID:", "Password:","Email ID:"}
typedef struct{
int id;
char *name;
char *userID;
char *pwd;
char *emailID;
} password;
password pw={0,"","","",""};
int step=1;
int padding=15;
int y1=7
int x1=0;
int x2=167
int row_1 = sizeof(REGISTER) / sizeof(REGISTER[0]);
for (int i=1; i<=row_1; i++){ // i is corretly initiaised to 1
j=(((x2-x1)-strlen(*(REGISTER+i)))/2)+strlen(*(REGISTER+i));
step += increment;
gotoxy(((x1-padding)+j), (y1+step));
if (i==1){
fflush(stdin);
scanf("%30[^\n]s",pw.name);
}
else if (i==2){
fflush(stdin);
scanf("%12s",pw.userID);
}
else if (i==3){
fflush(stdin);
scanf("%15s",pw.pwd);
}
else {
fflush(stdin);
scanf("%30s",pw.emailID);
}
}
My scanf is not working properly. For every iteration of i it first uses gotoxy and then scanf should take the value of properly field based on i.
I can't get this working properly. The cursor moves properly if no value is entered.
However, if a value is entered, it unpredictably terminates with an error or moves the cursor to somewhere and waits for input.
I only need to include spaces with the pw.name field.
NOTE: Using Code::blocks with gcc.