#include<stdio.h>
#include"student.h"
int main()
{
// student 1
STUDENT lux = Createstudent("2003056789-lux aa ren");
printf("NAME:%s\n", GetNameFromStudent(lux));
// student 2
STUDENT a = Createstudent("2004069876-bb cc");
printf("NAME:%s\n", GetNameFromStudent(a));
printstudent(a);
// student 3
STUDENT b = Createstudent("2003081234-DD EE gg");
printf("NAME:%s\n", GetNameFromStudent(b));
printstudent(b);
// student 4
STUDENT c = Createstudent("2003074521-QQ RR YY");
printf("NAME:%s\n", GetNameFromStudent(c));
printstudent(c);
// student 5
STUDENT d = Createstudent("2003017623-MM NN JJ");
printf("NAME:%s\n", GetNameFromStudent(d));
printstudent(d);
return 0;
}
header.file this is my header.file
#pragma once
#define MAXSIZE 25
typedef struct student
{
int studentnum;
char firstname[MAXSIZE];
char lasttname[MAXSIZE];
char middelname[MAXSIZE];
}STUDENT;
STUDENT Createstudent(int, char[], char[], char[]);
void printstudent(STUDENT);
the program asks me to print 5 different students and need to use a header.file I am not sure why had a C2198 error on my program I try to separate the student but I don't know how?
CodePudding user response:
Your prototype says STUDENT Createstudent(int, char[], char[], char[]);
takes 4 arguments (int, char[], char[], char[]
) but you call it STUDENT lux = Createstudent("2003056789-lux aa ren");
with 1 char []
argument "2003056789-lux aa ren".
You need to parse the string into individual elements, for instance, using sscanf(s, "%d-%s%s%s", &s->studentnum, s->firstname, s->middlename, s->lastname)
. Your second data entry only has 2 space separated words, so you need to figure out if that is bad data, or one of the 3 strings are optional. For instance, if you were only able to read 3 fields (sscanf()
tells you how many fields) then s->lastname = s->middlename; s->middlename = NULL;
This or very similar problem has been discussed a number of times so use the search feature if you need more help. For instance: CSV File Input in C using Structures