I've been fighting with this one for a little bit and I cant figure it out. The void printStudent(studentInfo); i've tried at printStudent(studentInfo *); and i've tried printStudent(studentInfo * stud); now I'm at this point where it compiles up to the fuction of printStudent(studentInfo * stud). I know this is such a simple fix that I'm missing it completely. Any ideas?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUMELTS 10
struct student_info {
char * firstname;
char * lastname;
char * major;
char * yearinschool;
int numcredits;
float* gpa;
};
struct studentInfo * student_list;
void printStudent(studentInfo);
void printAllStudents();
void addStudent();
void getStudentInfo();
int main()
{
char current = 'a';
printf("Welcome to the student manager.\n");
while (current != 'Q')
{
printf("Enter a choice:\n");
printf("[V]iew all students\n");
printf("[A]dd a student\n");
printf("[G]et info on a student.\n");
printf("[Q]uit.\n");
current = getc(stdin);
getc(stdin);
switch (current)
{
case 'V':
printAllStudents();
break;
case 'A':
addStudent();
break;
case 'G':
getStudentInfo();
break;
case 'Q':
printf("Thank You!\n");
getc(stdin);
break;
default:
printf("Error: Unknown command!\n");
}
}
return 0;
}
/************************** printstudent() **************************/
void printStudent(studentInfo * stud)
{
printf("First: %s\n", stud->firstname);
printf("\tLast: %s\n", stud->lastname);
printf("\tMajor: %s\n", stud->major);
printf("\tYear: %s\n", stud->yearinschool);
printf("\tCredits: %d\n", stud->numcredits);
printf("\tGPA: %f\n", stud->gpa);
}
/************************** printallstudents() **************************/
void printAllStudents()
{
struct studentInfo * current = student_list;
if (current != 0)
{
while (current != 0)
{
printStudent(current);
current = current->next;
}
else
{
printf("Error: No students have been entered yet!\n");
}
}
}
/************************** addstudent() **************************/
void addStudent()
{
printf("Creating a new student...\n");
studentInfo * temp = (struct studentInfo*) malloc(sizeof(struct studentInfo));
printf("\nEnter student first name:");
gets(temp->firstname);
printf("\nEnter student last name:");
gets(temp->lastname);
printf("\nEnter the student's grade:");
char buffer[8];
gets(buffer);
printf("\nEnter student major:");
gets(temp->major);
printf("\nEnter student year in school:");
gets(temp->major);
printf("\nEnter student credits:");
gets(temp->numcredits);
print("\nEnter student GPA:");
gets(temp->gpa);
printf("Adding student %s to the list...", temp->name);
temp->next = student_list;
student_list = temp;
printf("Done!\n");
}
/************************** getstudentinfo() **************************/
void getStudentInfo()
{
printf("Enter the name of a student:");
char search[32];
int found = 0;
gets(search);
printf("Searching the list...");
struct studentInfo * current = student_list;
while ((current != 0) && !found)
{
if (!strcmp(current->name, search))
{
found = 1;
}
else
{
current = current->next;
}
printf("Done!\n");
if (current != 0)
{
printStudent(current);
}
else
{
printf("No student by that name exists in the database\n");
}
}
}