Wednesday, 18 September 2013

C PROGRAM TO DEMONSTRATE STRUCTURES USING FUNCTIONS

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


struct personell
{
    char name[20];
    int agnumb;
};

struct personell newname(void);   //function for reading i/p and returns an structure
void agentlist(struct personell); //function takes the structure and displays it

int main()
{

    struct personell agent1;
    struct personell agent2;

    agent1=newname();
    agent2=newname();

    agentlist(agent1);
    agentlist(agent2);

    getchar();
    return 0;
}


struct personell newname()
{
    char numstr[20];
    struct personell agent;

    printf("enter agent name:");
    gets(agent.name);
    printf("enter agent number:");
    gets(numstr);
    agent.agnumb=atoi(numstr);
    return(agent);
}


void agentlist(struct personell agent)
{

    printf("\n agent name=%s",agent.name);
    printf("\nagent num=%d",agent.agnumb);
}

No comments:

Post a Comment