So last option is to post here else I dunno what to do,
I have this menu system for a Linux test program, C program. Lots of options and initially I had a scanf that worked fine. Then scanf stopped working, so I guess there were a lot of white spaces and new lines etc preventing me from entering an input ( Don't particularly understand that, because the first actual output to the screen/stdout is this menu system upon program start up).
Anyway, I then tried another option, which also worked for a while. The program when it displayed the menu system paused for a bit allowed me to enter an option and continued on its merry way..... AAAAAAannnnnd then stopped working resulting in segmentation fault error, using GDB if you don't enter any value it pops up with this seg fault error. Don't particularly understand how in one instance it will pause and allow me enter stuff and the next goes straight through and Seg fault.
Any Ideas as to why it worked and now stopped working?? Even if any of you do offer any solutions I think its only a matter of time when that breaks as well :(... So lost ... Any help greatly appreciated .
The code below is a copy n paste from a website,
char choice;
printf("\t\t\tMenu Title\n");
printf("Menu Item1\n");
printf("Menu Item2\n");
printf("Menu Item3\n");
printf("Menu Item4\n");
printf("Menu Item5\n");
choice = *(read_line());
char *read_line (void)
{
char *p;
char buf[100] = {0};
int length = 100;
if (p = fgets (buf, length, stdin)) {
size_t last = strlen (buf) - 1;
if (buf[last] == '\n') {
buf[last] = '\0';
} else {
fscanf (stdin, "%*[^\n]");
(void) fgetc (stdin);
}
}
return p;
}