Using structures, write the necessary declarations for Customers in a typical credit union in Cameroon.

Source Code

Brief explanation is provided after the source code.

typedef struct {

    long int account_number;
    char *first_name[45];
    char *last_name[45];
    char *profession[45];
    char *phone_number[9];
    long int cni;
    char *issued_on[10];
    char *at[5];

} CUSTOMER;

int main(int argc, char ** argv) {

    CUSTOMER cus;
    printf("Account Number: ");  scanf("%ld", &cus.account_number);
    printf("\nFirst Name: ");  scanf("%s", cus.first_name);
    printf("\nLast Name: ");  scanf("%s", cus.last_name);
    printf("\nProfession: ");  scanf("%s", cus.profession);
    printf("\nPhone Number: ");  scanf("%s", cus.phone_number);
    printf("\nCNI: ");  scanf("%ld", &cus.cni);
    printf("\nIssued On: ");  scanf("%s", cus.issued_on);
    printf("\nAt: ");  scanf("%s", cus.at);

    printf("\nAccount Number: ");  printf("%ld", cus.account_number);
    printf("\nFirst Name: ");   printf("%s", cus.first_name);
    printf("\nLast Name: ");   printf("%s", cus.last_name);
    printf("\nProfession: ");   printf("%s", cus.profession);
    printf("\nPhone Number: ");   printf("%s", cus.phone_number);
    printf("\nCNI: ");   printf("%ld", cus.cni);
    printf("\nIssued On: ");   printf("%s", cus.issued_on);
    printf("\nAt: ");   printf("%s\n", cus.at);


    return 0;
}

When you compile and execute the above program it produces the following result on Linux:

Account Number: 1000

First Name: Fokwa

Last Name: Divine

Profession: Programmer   

Phone Number: +237xxxxxxxxx

CNI: 123456789

Issued On: 04-06-2015

At: nw19

Account Number: 1000
First Name: Fokwa
Last Name: Divine
Profession: Programmer
Phone Number: +237xxxxxxxxx
CNI: 123456789
Issued On: 04-06-2015
At: nw19

Brief Explanation

  • A structure in C is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling.
  • Using typedef, CUSTOMER is created as a synonym for the structure. CUSTOMER is then use in the main function to define a variable cus of type structure. i.e CUSTOMER cus
  • scanf function reads data and assign to the fields define in the structure
  • Using printf function, the inputted data is displayed to the stdout.

Add comment


Security code
Refresh