I'm currently in the process of programming the largest C program I have ever written, for a final assignment for one of my university modules. The program is modular, containing files such as main.c, librarian.c, students.c, and books.c. Each has their corresponding header file and I also have a file, structs.h, containing two structures: one for books and one for students.
I'm currently facing a problem, where when the librarian tries to add a new student membership to the library, certain inputs are completely skipped over and I don't understand why.
I'll try and include as little code as possible but this may be a challenge due to the size of my program.
First, here's my student structure as it may be relevant:
struct STUDENT //Structure variable for student
{
int id;
char *name[20];
char *pass[20];
int mobile;
float fee;
int age;
char *cat;
};
struct STUDENT student;
Now, the function that is causing me problems is this:
int student_data(int answer){ //Function to add data of student to LIS
student_confirm();
int x = 15, x1 = 30;
int student_ID;
gotoxy(x,7);printf("Enter the Information Bellow");
gotoxy(x,10);printf("Student Name:"); gotoxy(x1,10);scanf(" %d",&student_ID);
if(student.id==student_ID){
gotoxy(x,11);printf("Id is already Exits");
getch(); add_student();
}
student.id=student_ID;
gotoxy(x,11);printf("User Name:");gotoxy(x1,11);scanf("%s",&student.name);
gotoxy(x,12);printf("Password:");gotoxy(x1,12);scanf("%s",&student.pass);
gotoxy(x,13);printf("Mobile:");gotoxy(x1,13);scanf("%d",&student.mobile);
gotoxy(x,14);printf("Fee:");gotoxy(x1,14);scanf("%f",&student.fee);
gotoxy(x,15);printf("Age:");gotoxy(x1,15);scanf("%d",&student.age);
return 1;
}
The student_confirm() function simply asks the user if they are sure they want to add a new student to the library. Now, when I run the program, I sign in as the librarian, go to add a student and am greeted with this in the console
*****Library Information System*****
***Brotherton Library***
*1975*
____________________________________________
Confirm you would like to add a new student: (Y/N)
Enter the Information Bellow
Student Name:
User Name:
Password:
It skips straight to Password, not allowing me to enter the prior two fields. I'm completely stumped by this. There's similar parts of code in my program (such as for adding books) that follow the same logic and they work just fine. I wasn't able to find anything via a search on here either.
Now, I've only been programming in C for about 6 months so I'm definitely a beginner. I'm becoming somewhat proficient but there's so much more to learn, and so much that I don't know about regarding the language.
Warnings I'm getting are:
warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char * (*)[20]' [-Wformat=]|
for both the fields that are skipped. Is this because arrays are technically pointers? I tried changing a few things around, but like I said my books struct uses exactly the same logic as the students one, and I have an add_books function which is more or less the same as the students one provided which works without any hiccups.
Any help would be greatly appreciated and hopefully this question can help others in the future. Thanks guys and gals.
edited to add the student_confirm() function:
int student_confirm(){ //Function to confirm adding of student
int x = 10;
char answer;
system("cls");window();
printf("\n\n\n");
gotoxy(x,5);printf("Confirm you would like to add a new student: (Y/N)");
if(getch() == 'y' || answer == 'Y')
student_data(answer);
return 1;
}