C语言 从 .txt文件 读取数据 写入到 .dat 二进制文件 fwrite写不进去

#include <QtCore/QCoreApplication>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
struct Date
{
int year;
int month;
int day;
};
struct Student
{
char no[16];
char name[16];
char sex[4];
struct Date birthday;
int score[4];

};
void bfCreat();
void bfPrint();
const int N = 3;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
bfCreat();
printf ("打印二进制文件:\n");
bfPrint ();
return a.exec();
}
void bfCreat()
{
FILE *pf = fopen("c:\\file3.txt","r");
if(pf == NULL)
{
perror("打开txt文件失败!\n");
exit(errno);
}
FILE *pf1 = fopen("c:\\file3.dat","wb");
if(pf1 = NULL)
{
perror("打开dat文件失败!\n");
exit(errno);
}
struct Student stu;
fscanf(pf,"%s %s %s %d %d %d %d %d %d %d",&stu.no, &stu.name, &stu.sex, &stu.birthday.year,
&stu.birthday.month, &stu.birthday.day, &stu.score[0],
&stu.score[1], &stu.score[2], &stu.score[3]);
while(!feof(pf))
{
fwrite (&stu, sizeof(stu), 1, pf1);
fscanf(pf,"%s %s %s %d %d %d %d %d %d %d",&stu.no, &stu.name, &stu.sex, &stu.birthday.year,
&stu.birthday.month, &stu.birthday.day, &stu.score[0],
&stu.score[1], &stu.score[2], &stu.score[3]);
}
fclose(pf);
fclose(pf1);

}

if(pf1 = NULL)
{
perror("打开dat文件失败!\n");
exit(errno);
}
这句有问题
if(pf1 == NULL)
{
perror("打开dat文件失败!\n");
exit(errno);
}
温馨提示:答案为网友推荐,仅供参考
相似回答