Wednesday, May 9, 2012

STRUCTURE POINTER

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

typedef struct tag{
    char name[20];
    char emailid[20];
    int age;

}ADDRESS_BOOK;

void show_name(ADDRESS_BOOK *emp);  /* function prototype */

int main(void)
{
     ADDRESS_BOOK ragu,*emp;
     emp=&ragu;
    sprintf(ragu.name,"praveen");
    sprintf(ragu.emailid,"veenrick@gmail.com");
    ragu.age=25;
     show_name(emp);          /* pass the pointer */
    return 0;
}

void show_name(ADDRESS_BOOK *p)
{
    printf("\n name %s ", p->name);  /* p points to a structure */
    printf("\n email %s ", p->emailid);
    printf("\n age %d", p->age);
}

No comments:

Post a Comment