for my assignment were making a bank database application and for the menu the user must be allowed to type "partial or full" option name. For example for 'add' they can type, add, ad, or a nothing else to call the add function. My problem is that when the user types just a i get a segfault error but when I type add or ad it works just fine. Heres my code AND IM SORRY I know the names and values and such are all over the place, the rest of the program is sitting in my text editor. I suspect that the problem resides around the: if (*firstCharA == 'a' || *firstCharA == 'A') area. Please save me
#include <stdio.h>
#include <string.h>
#include "record.h"
#include "database.h"
int debug = 0;
void getaddress(int, char [], char []);
int main ()
{
struct record * start = NULL;
int on = 0;
const char userInput[60];
int addRec;
const char add[7] = "add";
int printAllRec;
char printall[] = "printall";
int findRec;
char find[] = "find";
int deleteRec;
char delete[] = "delete";
int quitPro;
char quit[] = "quit";
printf("\nWelcome to the ZaeBank database! Here you can get all of your bank record needs from adding a record to finding a record!\n");
printf("To get started, type either add, printall or find and then hit enter!\n");
while (on < 1)
{
printf("\nadd: add a bank record and store it in the ZaeBank database\n");
printf("\nprintall: print all of the currcently existing bank records in the ZaeBank database\n");
printf("\nfind: find a currently existing bank record in the ZaeBank database\n");
printf("\ndelete: delete a currently existing bank record in the ZaeBank database\n");
printf("\nquit: type 'quit' to quit the program\n");
scanf("%s", &userInput);
char *firstCharA;
char *firstCharP;
char *firstCharF;
char *firstCharD;
char *firstCharQ;
firstCharA = strpbrk(userInput, add);
firstCharP = strpbrk(userInput, printall);
firstCharF = strpbrk(userInput, find);
firstCharD = strpbrk(userInput, delete);
firstCharQ = strpbrk(userInput, quit);
addRec = strcmp(userInput, add);
printAllRec = strcmp(userInput, printall);
findRec = strcmp(userInput, find);
deleteRec = strcmp(userInput, delete);
quitPro = strcmp(userInput, quit);
if (*firstCharA == 'a' || *firstCharA == 'A')
{
if (addRec == 0)
{
printf("1");
}
else if (addRec < 0)
{
printf("2");
}
}