Code
struct Student
{
unsigned int ID;
char name[256];
int FileLocLeft;
int FileLocRight;
int FileLocParent;
};
void main()
{
Student CurStudent;
FILE* fp = fopen("d:\\students.bat", "w");
if(fp == NULL)
{
printf("File not found\n");
}
else
{
fseek(fp,0,SEEK_SET);
CurStudent.FileLocLeft = 0;
CurStudent.FileLocParent = 0;
CurStudent.FileLocRight = 0;
CurStudent.ID = 0;
CurStudent.name = "Root";
fwrite(CurStudent,sizeof(Student),1,fp);
}
}
I’m having trouble with two errors, one is I cannot assign “Root” (const char[15]) to name (char[256]) and when using fwrite I get “cannot conver parameter 1 from ‘Student’ to ‘const void'”
You can’t assign to an array like that in C and
fwriteexpects a pointer, you can’t pass a struct. How about: