Home > Back-end > Help: failed to write data to a file
Help: failed to write data to a file
Time:09-29
First came to this BBS, I recently in self-study Tan Haoqiang C language program design, file operations in the final chapter part I've always wanted to own field, and write the copy is a textbook example of probably write data to a file of the program, but has been written to failure, I find for a long time, but pretty good where is no problem, here is the code: #include #include # define N 2 Struct Student_type { Int num. Char name [10]. int age; Char addr [25]; }; Struct Student_type stud [N].
Int main () { The FILE * fp. int i; If ((fp=fopen (" C: \ \ Users \ \ ASUS \ \ Documents \ \ \ \ C - Free practice \ \ "dat", "wb")==NULL)) { Printf (" Can not open this file! \n"); exit(0); } Printf (" do enter the student data. The format is: \ nNo \ t | Name \ t | Age \ t | Address \ t \ n "); for(i=0; i{ The scanf (" % d % d % s % s ", & amp; Stud [I]. Num, stud [I]. Name, & amp; Stud [I]. Age, stud [I] addr); If (fwrite (& amp; Stud [I], sizeof (struct Student_type), 1, fp)! =1){ Printf (" the File write error! \n"); } } The fclose (fp); return 0; } Program is running process: And compile time there will be a warning: the assignment top service pointer from integer without a cast warning