M
Maxx
I'm writing this program that can store information about 50 students
and prints them. I was using pointer to structure construct in this
program, the program gets compiled well with 0 errors but the program
is not printing any output and i'm getting a unhandled exception.
Here is the program::::
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 100
typedef struct _student
{
char name[25],dept[2],address[50],d_o_b[10];
int age,roll;
}STUDENT;
STUDENT stdnt_arr[MAX_LEN];
int sn=0;
void get_input();
void rec_pr();
int main()
{
char c,chrin[50],nr;
printf("\t\tWelcome to student database\nChoose The following
option");
printf("I- Input Record\tP- Print Record\n");
c=getchar();
switch(c)
{
case 'I':
get_input();
break;
case 'P':
rec_pr();
break;
default:
fprintf(stderr,"No option selected");
exit(2);
}
printf("\nNow Exiting::");
return 0;
}
void get_input()
{
stdnt_arr[sn]=(STUDENT *)malloc(sizeof(STUDENT));
printf("Enter Your Name::");
scanf("%s",stdnt_arr[sn]->name);
printf("Enter Your Dept::");
scanf("%s",stdnt_arr[sn]->dept);
printf("Enter Your address::");
scanf("%s",stdnt_arr[sn]->address);
printf("Enter your age::");
scanf("%d",&stdnt_arr[sn]->age);
printf("%d\n",stdnt_arr[sn]->age);
printf("Enter your roll no::");
scanf("%d",&stdnt_arr[sn]->roll);
printf("Enter your date of birth::");
scanf("%s",stdnt_arr[sn]->d_o_b);
sn++;
}
void rec_pr()
{
printf("Name::%s",stdnt_arr[0]->name);
printf("Dept::%s",stdnt_arr[0]->dept);
printf("Address::%s",stdnt_arr[0]->address);
printf("Age::%d",stdnt_arr[0]->age);
printf("Roll_no::%d",stdnt_arr[0]->roll);
printf("Date of Birth::%s",stdnt_arr[0]->d_o_b);
}
The get_input() function is working well but the rec_pr() is giving me
a unhandled exception when running... Please help me through this
and prints them. I was using pointer to structure construct in this
program, the program gets compiled well with 0 errors but the program
is not printing any output and i'm getting a unhandled exception.
Here is the program::::
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 100
typedef struct _student
{
char name[25],dept[2],address[50],d_o_b[10];
int age,roll;
}STUDENT;
STUDENT stdnt_arr[MAX_LEN];
int sn=0;
void get_input();
void rec_pr();
int main()
{
char c,chrin[50],nr;
printf("\t\tWelcome to student database\nChoose The following
option");
printf("I- Input Record\tP- Print Record\n");
c=getchar();
switch(c)
{
case 'I':
get_input();
break;
case 'P':
rec_pr();
break;
default:
fprintf(stderr,"No option selected");
exit(2);
}
printf("\nNow Exiting::");
return 0;
}
void get_input()
{
stdnt_arr[sn]=(STUDENT *)malloc(sizeof(STUDENT));
printf("Enter Your Name::");
scanf("%s",stdnt_arr[sn]->name);
printf("Enter Your Dept::");
scanf("%s",stdnt_arr[sn]->dept);
printf("Enter Your address::");
scanf("%s",stdnt_arr[sn]->address);
printf("Enter your age::");
scanf("%d",&stdnt_arr[sn]->age);
printf("%d\n",stdnt_arr[sn]->age);
printf("Enter your roll no::");
scanf("%d",&stdnt_arr[sn]->roll);
printf("Enter your date of birth::");
scanf("%s",stdnt_arr[sn]->d_o_b);
sn++;
}
void rec_pr()
{
printf("Name::%s",stdnt_arr[0]->name);
printf("Dept::%s",stdnt_arr[0]->dept);
printf("Address::%s",stdnt_arr[0]->address);
printf("Age::%d",stdnt_arr[0]->age);
printf("Roll_no::%d",stdnt_arr[0]->roll);
printf("Date of Birth::%s",stdnt_arr[0]->d_o_b);
}
The get_input() function is working well but the rec_pr() is giving me
a unhandled exception when running... Please help me through this