Hi all,
I was making a program as one of our activities. The output should be something like this:
[IMG]http://img10.imageshack.us/i/ss1qh.jpg/[/IMG]
When I press on Display Output, it should look like this:
[IMG]http://img29.imageshack.us/i/ss2pa.jpg/[/IMG]
However, when I have to Insert a record, the added record should be added on the record when I have to display them. I have my program below, but I can't seem to get how to do that. Please bear with me.
#include<stdio.h>
#include<stdlib.h>
#define x 20
int index=1,ans,as,ctr;
struct student
{
char studname[20];
char course[6];
int yr;
} studinfo [x];
void addrec()
{
printf("\n\nHow many record(s) do you want to store? ");
scanf("%d",&as);
printf("\n\n");
for(ctr=0;ctr<as;ctr++)
{
printf("Record Number %d\n\n",index++);
printf("Name : ");
scanf("%s",&studinfo[ctr].studname);
printf("Course : ");
scanf("%s",&studinfo[ctr].course);
printf("Year : ");
scanf("%d",&studinfo[ctr].yr);
}
}
void insertrec()
{
printf("\n\nHow many record(s) do you want to Add? ");
scanf("%d",&as);
printf("\n\n");
for(ctr=0;ctr<as;ctr++)
{
printf("Record Number %d\n\n",index++);
printf("Name : ");
scanf("%s",&studinfo[ctr].studname);
printf("Course : ");
scanf("%s",&studinfo[ctr].course);
printf("Year : ");
scanf("%d",&studinfo[ctr].yr);
}
}
void displayrec()
{
system ("cls");
printf ("\n\n\t\t Student Name \tCourse \tYear\n\n");
for(ctr=0;ctr<as;ctr++)
{
printf("\t\t %s\t\t %s\t %d\n",studinfo[ctr].studname,studinfo[ctr].course,studinfo[ctr].yr);
}
printf ("\n\n");
}
void main()
{
start:
printf("\n[1]-ADD NEW RECORD\n[2]-INSERT RECORD\n[3]-DISPLAY RECORDS\n[4]-EXIT\n\n");
printf("Enter desired transaction: ");
scanf("%d",&ans);
if(ans==1)
{
addrec();
goto start;
}
else if(ans==2)
{
insertrec();
goto start;
}
else if(ans==3)
{
displayrec();
goto start;
}
else
printf("\nYou have chosen to EXIT this program!\n");
}