I am working on a program to create a simple customer database that stores customer names and their SSNs. The program should allow the user to add records, delete, print, and search.
I just created the add customer (addcust) function. The program compiles without a problem but the problem is that when I execute the code and choose the Add Customer Option, and enter a customer name, the program prints "enter customer name" twice, before printing "Enter SSN".
I guess you will only understand what I am saying if you execute this, so I have attached the code. Any help will be greatly appreciated. It probably is something small that I have overlooked but my brain is totally fryed right now so I cant think
Thanks guys.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void addcust(void);
void delcust(void);
void printcust(void);
void findcust(void);
void searchcust(void);
void savetofile(void);
void nosave(void);
struct customer {
char name[25];
char ssn[15];
struct customer * next;
} ;
int main(char ch)
{
printf("\n\nCUSTOMER INFORMATION DATABASE\n\n");
printf("A - ADD Customer\n");
printf("D - DELETE Customer\n");
printf("P - PRINT Database\n");
printf("F - FIND Customer Name by SSN\n");
printf("S - SEARCH Customer SSN by Name\n");
printf("Q - QUIT Without Saving\n");
printf("E - SAVE and Exit\n\n");
printf("Enter a Letter, or E to quit without saving.\n");
while ((ch=getchar()) != 'E')
{
switch(ch)
{
case 'a' :
case 'A' : addcust();
break;
case 'd' :
case 'D' : delcust();
break;
case 'p' :
case 'P' : printcust();
break;
case 'f' :
case 'F' : findcust();
break;
case 's' :
case 'S' : searchcust();
break;
case 'q' :
case 'Q' : savetofile();
break;
case 'e' :
case 'E' : nosave();
break;
default : break;
}
}
return ch;
}
void addcust(void)
{
struct customer * head = NULL;
struct customer * prev, * current;
char customer[25];
puts("Enter first customer: ");
while (gets(customer) != NULL && customer[0] != '\0')
{
current = (struct customer *) malloc(sizeof(struct customer));
if (head == NULL)
head = current;
else
prev->next=current;
current->next = NULL;
strcpy(current->name, customer);
puts("Enter SSN:");
scanf("%s", current->ssn);
while(getchar() != '\n')
continue;
puts("Enter next customer name (empty line to stop):");
prev=current;
}
}
void delcust(void){}
void printcust(void){}
void findcust(void){}
void searchcust(void){}
void savetofile(void){}
void nosave(void){}