What I mean is doing something like this:
Code:
#include <stdio.h>
#include <string.h>
struct Customer
{
int AccNum;
char CustName;
double CustBalance;
};
void initCustomers(struct Customer customers[], size_t num);
void printCustomerData(const struct Customer customers[], size_t num);
#define NUM_CUSTOMERS 5
int main(void)
{
struct Customer customers[NUM_CUSTOMERS];
initCustomers(customers, NUM_CUSTOMERS);
printCustomerData(customers, NUM_CUSTOMERS);
return 0;
}
/* Prompts user for customer data to populate array of customers */
void initCustomers(struct Customer customers[], size_t num)
{
for (size_t i = 0; i < num; i++)
{
printf("\nEnter Account Number >>");
scanf("%d", &customers[i].AccNum);
printf("\nEnter Customer Name >>");
scanf("%s", &customers[i].CustName);
printf("\nEnter Customer's Balance >>");
scanf("%lf", &customers[i].CustBalance);
}
printf("Please Wait....\n");
}
/* ... */
You should also note that using scanf with %s without a field width results in a buffer overflow vulnerability: you should specify a field width equal to the maximum length of the string... which leads us to the next problem: CustName is a char, not an array of char that could store a string.