Hey all!
Got some problems with basic file I/O on binary file. It seems like i can write to the file bacause its beeing created. But when i type in information, write it to file, and then reading from file, it seems OK. But if i close the program and try to open the file, all that its printed are just jibberish.
// My defines
My struct:Code:#define TY 20 #define FY 50 #define HD 100 #define TI sizeof(struct TestInfo) #define CO sizeof(struct Course)
My write to file:Code:struct Course { char kurskod[TY]; char kursnamn[TY]; char inst[TY]; char larare[TY]; char kurskommentar[FY]; };
My read from file:Code:void write_to_file(struct Course *co) { FILE *fp; fp=fopen("courseinfo.bin", "wb"); fwrite(&co,CO,1, fp); fclose(fp); }
The way i call them:Code:void read_from_file(struct Course *co) { FILE *inFile; if(!(inFile = fopen("courseinfo.bin", "r"))) fread(&co,CO,1,inFile); fclose(inFile); }
Code:struct Course new_course; read_from_file(&new_course); write_to_file(&new_course);
Can anyone see whats from with my functions (or something else for that matter)?
Regards
/Henrik!



LinkBack URL
About LinkBacks



