Program to to read and display data of students using an array of pointers

#include<stdio.h>

    struct dob1
    {
        int date;
        int month;
        int year;
    }dob;

    struct student
    {
        int rno;
        char fname[80];
        char lname[80];
        int fees;
    } 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]=dob.date;
        p[j+3]=dob.month;
        p[j+4]=dob.year;
        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 date of birth [DD/MM/YYYY respectively] of student no. %d\n",i+1);
        scanf("%d",&p[j+2]);
        scanf("%d",&p[j+3]);
        scanf("%d",&p[j+4]);
        j=j+5;
        k=k+2;
        l=l+30;
        m=m+30;

    }
    j=0;
    k=0;
    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("Roll no. of student - %d\n",p[j]);
        printf("Fees - %d\n",p[j+1]);
        printf("Date of birth - %d/%d/%d\n",p[j+2],p[j+3],p[j+4]);
        printf("\n\n\n_______________________________________________\n\n\n\n");
        l=l+30;
        m=m+30;
        j=j+5;
        k=k+2;

    }
}

Output:

21_3

Leave a Reply

Your email address will not be published.