Passing members of structure student by using call by reference.

#include<stdio.h>

    struct student
    {
        int rno;
        char fname[80];
        char lname[80];
        int fees;
        int class;
    } stud;

main()
{

    int n,i,j=0,k=0,l=0,m=0;
    int *p[100];
    char *q[1000];

    printf("Enter no. of students\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        p[j]=stud.rno;
        p[j+1]=stud.fees;
        p[j+2]=stud.class;
        q[k]=&stud.fname[l];
        q[k+1]=&stud.lname[m];
        printf("Enter the first name of student no. %d\n",i+1);
        scanf("%s",q[k]);
        printf("Enter the last name of student no. %d\n",i+1);
        scanf("%s",q[k+1]);
        printf("Enter the roll no. of student no. %d\n",i+1);
        scanf("%d",&p[j]);
        printf("Enter the fees of student no. %d\n",i+1);
        scanf("%d",&p[j+1]);
        printf("Enter the class of student no. %d\n",i+1);
        scanf("%d",&p[j+2]);

        j=j+3;
        k=k+2;
        l=l+30;
        m=m+30;

    }
    func(&p,&q,n);
}

int func(int *p, int *q, int n)
{

    int j=0,k=0,i,l,m;

    printf("\n\n\nInformation of students are as follows:\n\n\n\n_______________________________________________\n\n\n");

    for(i=0;i<n;i++)
    {
        printf("Information of student no. %d\n",i+1);
        printf("Name of the student - %s %s\n",q[k],q[k+1]);
        printf("Class - %d\n",p[j+2]);
        printf("Roll no. of student - %d\n",p[j]);
        printf("Fees - %d\n",p[j+1]);

        printf("\n\n\n_______________________________________________\n\n\n\n");
        l=l+30;
        m=m+30;
        j=j+3;
        k=k+2;

    }
}

 

Output:

14_2

Leave a Reply

Your email address will not be published.