Saturday, December 15, 2012

Example for Dot and arrow usage of structural pointer and array.

# include <stdio.h>
# include <stdlib.h>
# include <string.h>


typedef struct database
{
    int age;
    char name[10];

}DATA;

DATA Str;
DATA *Ptr;




int main()
 {


    /*********** Dot format to Arrow format representation********/

     //Enter the values for database
    printf("1. Enter the values for database\n");
    printf("Enter your Age\n");
    scanf("%d",&(Str.age));
    scanf("%s",Str.name);

    printf("Your Age:%d is updated in database\n",(&Str)->age);
    printf("Your Name:%s is updated in database\n",(&Str)->name);
    /**************************************************************/



    Ptr =(DATA *)malloc(sizeof(DATA));
    /*********** Arrow format to Dot format representation *********/

        printf("2. Enter the values for database\n");
        printf("Enter your Age\n");
        scanf("%d",&(Ptr)->age);

        scanf("%s",Ptr->name);

        printf("Your Age:%d is updated in database\n",((*Ptr).age));
        printf("Your Name:%s is updated in database\n",(*Ptr).name);
    /**************************************************************/

     return 0;
 }


Output:


F:\workspace\pointer_C\Debug>pointer_C.c.exe
1. Enter the values for database
Enter your Age
24
kumar
Your Age:24 is updated in database
Your Name:kumar is updated in database
2. Enter the values for database
Enter your Age
23
Ramesh
Your Age:23 is updated in database
Your Name:Ramesh is updated in database

F:\workspace\pointer_C\Debug>

No comments:

Post a Comment