Hi there,
This is my first time working with an unsafe language, so naturally my first code would be full of memory-related bugs. I still have no idea how I ought to approach some of the problems I've been getting, and I've been resisting asking for help as much as I could.
The assignment I've been given is a buttload of work, so I'd rather not bog anyone down with too much of it. At the moment, I'm trying to work out how to design a menu() function that gives main() both the function choice the user wants and the arguments for that function. Here's what I've got so far:
struct REPLY {
char use[256];
char pass[256];
char type[64];
char nuse[256];
char npass[256];
char ntype[64];
int option;
};
struct REPLY *reply;
int menu (void)
{
int o;
printf("Please type a number corresponding to the following options:\n");
printf("1. Add\n");
printf("2. Delete\n");
printf("3. Edit\n");
printf("4. Purge\n");
printf("5. Quit\n");
scanf("Selection: %i\n", o);
reply->option=o;
printf("\n\n%i\n\n\n", reply->option);
switch(reply->option){
case '1':
{
printf("Please provide the username.\n");
scanf("%s\n", &reply->use);
printf("Please provide the password.\n");
scanf("%s\n", &reply->pass);
printf("Please provide the user type.\n");
scanf("%s\n", &reply->type);
break;
}
case '2':
{
printf("Please provide the username.\n");
scanf("%s\n",&reply->use);
break;
}
case '3':
{
printf("Please provide the username.\n");
scanf("%s\n",&reply->use);
printf("Please provide the password.\n");
scanf("%s\n",&reply->use);
printf("Please provide the new username.\n");
scanf("%s\n",&reply->nuse);
printf("Please provide the new password.\n");
scanf("%s\n",&reply->npass);
printf("Please provide the new user type.\n");
scanf("%s\n",&reply->ntype);
break;
}
case '4':
{
break;
}
case '5':
{
break;
}
}
return 0;
}
This code is saved as menu.c, which is included in the inclusion statements of the main function. I'm getting a segmentation fault at
reply->option=o;
and I haven't been able to find out why. I also get the sense main won't be able to access reply for some reason.
I just need a push, and it's probably so simple it went over my head, but can someone help me out?