For some reason whenever I enter an integer value to the integer type member of the struct, and then printing them, I get insanely high values. What am I doing wrong? I absolutely have no idea, please help D:
EDIT: printing the struct without '&' characters in front of the variable name makes the program crash (so the current code crashes for me), but when I add them, the integer members have completely bad values, however the character ones are fine.
Code:
#include <stdio.h>
struct rec1 {
char* Code;
char* Name;
int StudentMax;
int StudentIn;
} Subject[2];
int main()
{
int i;
int j;
for(i = 0; i <= 1; i++)
{
printf("Subject[%d].Code = ",i);
scanf("%s", &Subject[i].Code);
printf("Subject[%d].Name = ",i);
scanf("%s", &Subject[i].Name);
printf("Subject[%d].StudentMax = ",i);
scanf("%d", &Subject[i].StudentMax);
printf("Subject[%d].StudentIn = ",i);
scanf("%d", &Subject[i].StudentIn);
}
for(j = 0; j <= 1; j++)
{
printf("Subject[%d].Code = %s \n",j,Subject[j].Code);
printf("Subject[%d].Name = %s \n",j,Subject[j].Name);
printf("Subject[%d].StudentMax = %d \n",j,Subject[j].StudentMax);
printf("Subject[%d].StudentIn = %d \n",j,Subject[j].StudentIn);
}
return 0;
}