Showing posts with label Defining and accessing structures members. Show all posts
Showing posts with label Defining and accessing structures members. Show all posts

Defining and accessing structures members

Program 47) Define a structure type, struct personal that would contain person name, data of joining and salary. Using this structure, write a program to read this information for one person from the keyboard and print the same on the screen.

Structure definition along with the program is shown below. The scanf and printf functions illustrate how the member operator '.' is used to link the structure member to the structure variables. The variable name with a period and the member name is used like an ordinary variable.

                               PROGRAM

struct personal
{
        char name [20] ;
        int day ;
        char month [10] ;
        int year ;
        float salary ; 
} ;
main ( )
 {
     struct personal person ;
     printf ("Input values\n") ;
     scanf ("%s %d %s %f",person.name, &person.day,
                    person.month, &person. year, person salary) ;
 }

Output:         Input values
                      M .L.Geol    10  January  1945  4500
                      M.L.Goel     10  January  1945  4500.00