I'm creating a simple program using the C programming language. Unfortunately, I'm having a problem with a piece of source code right now. I am not able to store data in the students structure after running the program.
I think the problem is the gets() function in the ADD_Students() function. (Line 60)
Here is my source code: (Used code blocks with gnu gcc compiler in windows 10)
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define MAX 3
struct Students
{
char * Name;
char * Field;
char * City;
unsigned int Student_ID;
float Mark;
}Addr_INFO[MAX];
char Menu();
void ADD_Students();
void DEL_Students();
void EDT_Students();
int main()
{
char Selected_ITEM;
while (TRUE)
{
Selected_ITEM = Menu();
switch (Selected_ITEM)
{
case '1' : ADD_Students(); break;
case '2' : DEL_Students(); break;
case '3' : EDT_Students(); break;
default : printf("Wrong number!\n"); exit(0);
}
}
}
char Menu()
{
char Chose;
printf(".----------+ Students information management +----------.\n\n");
printf("[1]. ADD student\n");
printf("[2]. DEL student\n");
printf("[3]. EDT student\n\n");
printf("Please enter your choice: ");
scanf("%c", &Chose);
return Chose;
}
void ADD_Students()
{
register int i;
for (i = 0; i < MAX; i++)
{
printf("[S-%d]. Name: ", i);
gets(Addr_INFO[i].Name);
printf("[S-%d]. Field: ", i);
gets(Addr_INFO[i].Field);
printf("[S-%d]. City: ", i);
gets(Addr_INFO[i].City);
printf("[S-%d]. ID: ", i);
scanf("%d", &Addr_INFO[i].Student_ID);
printf("[S-%d]. Mark: ", i);
scanf("%.2f", &Addr_INFO[i].Mark);
printf("\n");
}
}
void DEL_Students()
{
printf("Test2");
}
void EDT_Students()
{
printf("Test3");
}
what's going on?
Why this is happened?
Ouput
.----------+ Students information management +----------.
[1]. ADD student
[2]. DEL student
[3]. EDT student
Please enter your choice: 1
[S-0]. Name: [S-0]. Field: [S-0]. City: [S-0]. ID: