So i'm new to C and i have a problem with struct, so when i run the program it goes to the_struct2 asks for first name and thats it. why does it stop working? is there a way to make the code more efficient? and is there a way to ask the user to enter number of students which records will be entered to define the number of inputs instead of making it exactly 6 based on structures. I read something regarding the Global variable but couldn't find out how to use it with structures.
P.S the purpose of the program is to take students last name, first name and score and save them so the user could call one of the functions listed at the end print statement (which i am working on still).
Thank you in advance.
#include<stdio.h>
#include <stdlib.h>
struct the_struct
{
char *FirstName[20];
char *LastName[32];
int *Score[20];
};
struct the_struct2
{
char *FirstName[20];
char *LastName[32];
int *Score[20];
};
struct the_struct3
{
char *FirstName[20];
char *LastName[32];
int *Score[20];
};
struct the_struct4
{
char *FirstName[20];
char *LastName[32];
int *Score[20];
};
struct the_struct5
{
char *FirstName[20];
char *LastName[32];
int *Score[20];
};
struct the_struct6
{
char *FirstName[20];
char *LastName[32];
int *Score[20];
};
int main ()
{
int i;
struct the_struct *ptr;
printf("Enter First Name \n");
scanf("%s",ptr->FirstName);
printf("Enter Last Name \n");
scanf("%s",ptr->LastName);
printf("Enter Score? \n");
scanf("%s",ptr->Score);
printf("%s %s %s",ptr->FirstName,ptr->LastName,ptr->Score);
//_____________________________________________________________
struct the_struct2 *ptr1;
printf("Enter First Name \n");
scanf("%s",ptr1->FirstName);
printf("Enter Last Name \n");
scanf("%s",ptr1->LastName);
printf("Enter Score? \n");
scanf("%s",ptr1->Score);
printf("%s %s %s",ptr1->FirstName,ptr1->LastName,ptr1->Score);
//__________________________________________________________________
struct the_struct3 *ptr2;
printf("Enter First Name \n");
scanf("%s",ptr2->FirstName);
printf("Enter Last Name \n");
scanf("%s",ptr2->LastName);
printf("Enter Score? \n");
scanf("%s",ptr2->Score);
printf("%s %s %s",ptr2->FirstName,ptr2->LastName,ptr2->Score);
//____________________________________________________________________
struct the_struct4 *ptr3;
printf("Enter First Name \n");
scanf("%s",ptr3->FirstName);
printf("Enter Last Name \n");
scanf("%s",ptr3->LastName);
printf("Enter Score? \n");
scanf("%s",ptr3->Score);
printf("%s %s %s",ptr3->FirstName,ptr3->LastName,ptr3->Score);
//___________________________________________________________________
struct the_struct5 *ptr4;
printf("Enter First Name \n");
scanf("%s",ptr4->FirstName);
printf("Enter Last Name \n");
scanf("%s",ptr4->LastName);
printf("Enter Score? \n");
scanf("%s",ptr4->Score);
printf("%s %s %s",ptr4->FirstName,ptr4->LastName,ptr4->Score);
//_________________________________________________________________
struct the_struct6 *ptr5;
printf("Enter First Name \n");
scanf("%s",ptr5->FirstName);
printf("Enter Last Name \n");
scanf("%s",ptr5->LastName);
printf("Enter Score? \n");
scanf("%s",ptr5->Score);
printf("%s %s %s",ptr5->FirstName,ptr5->LastName,ptr5->Score);
//Starting the function for entries.
printf("Enter the command you want to proceed to.\nprint record (press 1)\nadd new records (press 2)\ndelete record (press 3)\nSearch by last name (press 4)\nSort by score(press 5)\nSort by last name( press 6)\nFind Median score(press 7)\nExit program (press 0)");
return 0;
}