Ok so I tried to search and didnt come up with anything so if this has been posted before, I am sorry. I am new to C programming and have done well in my class so far up till now, the teacher says that this is the hardest program and I have spent hours on it with nothing. I had my mom look at it who works for IBM, sister who has taken the class before and my brother in law who is a computer engineer and none could tell me what I have done wrong.
#include <stdio.h>
#include <stdlib.h>
#define NAME_LEN 3
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 fillInTheCustInfo(int i)
{
Customer cust;
printf("Enter Data for Customer %d", i);
printf("\nEnter First Last Phone: ");
scanf("%s %s %s", cust.firstName, cust.lastName, cust.phone);
printf("\nEnter Address (Street City State ZIP): ");
scanf("%s %s %s %d", cust.street, cust.city, cust.state, &cust.zip);
return cust;
}
void printCustArray(Customer cust)
{
//printf("The Data for Customer %d is", i); this line keeps getting flagged also
printf("\nFirst: %s, Last: %s Phone: %s", cust.firstName, cust.lastName, cust.phone);
printf("\nAddress (Street City State ZIP): %s %s %s %d", cust.street, cust.city, cust.state, cust.zip);
}
int main() {
Customer custArray[NAME_LEN];
int i;
char stateCode[3];
for(i = 0; i < NAME_LEN; ++i)
{
custArray[i] = fillInTheCustInfo(i);
}
printf("Enter 2-character state code: ");
scanf(" %c",&stateCode);
for(i = 0; i < NAME_LEN; ++i)
{
if (custArray[NAME_LEN].state == stateCode); //this is the line I am having a problem with
printCustArray(custArray[i]);
}
system("pause");
return (0);
}
my output is
Enter Data for Customer 0
Enter First Last Phone: Doug Jones 123-456-7890
Enter Address (Street City State ZIP): Main Portland CO 12345
Enter Data for Customer 1
Enter First Last Phone: Doug Washington 123-456-7890
Enter Address (Street City State ZIP): Main Portland WA 12345
Enter Data for Customer 2
Enter First Last Phone: Another Colorado 123-456-7890
Enter Address (Street City State ZIP): Main Portland CO 12345
Enter 2-character state code: CO
First: Doug, Last: Jones Phone: 123-456-7890
Address (Street City State ZIP): Main Portland CO 12345
First: Doug, Last: Washington Phone: 123-456-7890
Address (Street City State ZIP): Main Portland WA 12345
First: Another, Last: Colorado Phone: 123-456-7890
Address (Street City State ZIP): Main Portland CO 12345Press any key to continue
. . .
Mine is listing all info entered.
The output is supposed to look like
Enter Data for Customer 0
Enter First Last Phone: Doug Oregon 123-456-7890
Enter Address (Street City State ZIP): Main Portland OR 12345
Enter Data for Customer 1
Enter First Last Phone: Doug Washington 123-456-7890
Enter Address (Street City State ZIP): Main Portland WA 12345
Enter Data for Customer 2
Enter First Last Phone: Doug California 123-456-7890
Enter Address (Street City State ZIP): Main Portland CA 12345
Enter Data for Customer 3
Enter First Last Phone: Doug Nevada 123-456-7890
Enter Address (Street City State ZIP): Main Portland NV 12345
Enter Data for Customer 4
Enter First Last Phone: Doug Colorado 123-456-7890
Enter Address (Street City State ZIP): Main Portland CO 12345
Enter Data for Customer 5
Enter First Last Phone: Another Colorado 123-456-7890
Enter Address (Street City State ZIP): Main Portland CO 12345
Enter Data for Customer 6
Enter First Last Phone: Doug Arizona 123-456-7890
Enter Address (Street City State ZIP): Main Portland AZ 12345
Enter Data for Customer 7
Enter First Last Phone: Doug Florida 123-456-7890
Enter Address (Street City State ZIP): Main Portland FL 12345
Enter Data for Customer 8
Enter First Last Phone: Doug Georgia 123-456-7890
Enter Address (Street City State ZIP): Main Portland GA 12345
Enter Data for Customer 9
Enter First Last Phone: Doug Jones 123-456-7890
Enter Address (Street City State ZIP): Main Portland CO 12345
Enter 2-character state code: CO
Data for Customer 4
Account: 4
Name: Doug Colorado
Addr: Main Portland CO 12345
Phone: 123-456-7890
Data for Customer 5
Account: 5
Name: Another Colorado
Addr: Main Portland CO 12345
Phone: 123-456-7890
Data for Customer 9
Account: 9
Name: Doug Jones
Addr: Main Portland CO 12345
Phone: 123-456-7890