I'm totally new to programming and taking an intro class. When i prompt the user for a state code the program just exits, nothing in my book really goes over this and all im given is crappy youtube videos for reference. Any help is greatly appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 2 // initially to test kept it to SIZE 2
typedef struct {
char firstName[30];
char lastName[30];
char street[35];
char city[20];
char state[3];
int zip;
char phone[15];
int accountId;
} Customer;
Customer getCustInfo(int a )
{
Customer cust;
char firstName2[30];
printf(" Enter Data for Customer %d\n", a);
printf("Enter First Last Phone: ");
scanf("%s %s %s", cust.firstName, cust.lastName, cust.phone);
printf("Enter Address (Street City State ZIP): \n");
scanf("%s %s %s %d", cust.street, cust.city, cust.state, &cust.zip);
cust.accountId = a + 1;
return cust;
}
void printCustDB(Customer cust)
{
printf("Data for Customer %d\n", cust.accountId);
printf(" First Last Phone: %s %s %s \n", cust.firstName, cust.lastName, cust.phone);
printf(" Address (Street City State ZIP): %s %s %s %d\n", cust.street,cust.city,cust.state, cust.zip);
}
int main(void)
{
Customer custDB[SIZE]; // an array of Customer type of size SIZE
int i;
char stateCode[3];
for (i = 0; i < SIZE; ++i)
{
custDB[i] = getCustInfo(i);
}
printf("Enter 2-character state code: ");
scanf("%s",stateCode);
for(i=0;i<SIZE;i++)
{if (custDB[i].state==stateCode)
printCustDB(custDB[i]);
}
system("pause");
return (0);
}