我想用c语言将数据txt文件 可是写入的都是空的 读取的也没有 自己去查看了txt文件 发现 文件大小是改变了的 但是里面只有空格 。有遇到过相同情况的小伙伴吗。
源码如下:
void AddStudent() {
if ((fp = fopen("sxsy.txt","a+"))== NULL) {//这里是打开文件(问题可能的地方)
return;
}
for (int i = 0; fscanf(fp, "%s %s ", stu[i].num, stu[i].name) != EOF; i++, n++);
cleardevice();
BeginBatchDraw();//缓冲作用 开始绘制UI 不显示
putimage(0, 0, &backTmg);
setbkmode(TRANSPARENT);
setcolor(BLUE);
settextstyle(50, 0, _T("华康少女文字W5(p)"));
outtextxy(200, 40, _T("录 入 学 生"));
EndBatchDraw();//结束绘制 把之前所有内容显示出来
int flag = 1;
for (int i = 100; i < 420; i += 32,flag = -flag) {//色彩变换
if (flag==1)
setfillcolor(RGB(1, 124, 235));
else
setfillcolor(RGB(255, 255, 255));
fillrectangle(60, i, 580, i+32);
}
setcolor(RED);
settextstyle(26, 0, _T("华康少女文字W5(p)"));
outtextxy(65, 105, _T("请输入学号:"));
char ch;
int x = 225,i=0;
while ((ch=getch())!=VK_RETURN) {//输入不等于回车时,文字位移
outtextxy(x, 105,ch);
*(stu[n].num + 1) = ch;
x += 18;
i++;
}
outtextxy(65, 136, _T("请输入姓名:"));
x = 225;
while ((ch = getch()) != VK_RETURN) {
outtextxy(x, 137, ch);
x += 18;
}
fprintf(fp, "%s %s ", stu[n].num, stu[n].name);//这里是保存数据(问题可能的地方)
n++;
fclose(fp);
outtextxy(220, 390, _T("正在保存...."));
Sleep(1000);
}
文件后缀 *.cpp
编译环境 vs2015 多字节字符集
麻烦各位了
源码如下:
void AddStudent() {
if ((fp = fopen("sxsy.txt","a+"))== NULL) {//这里是打开文件(问题可能的地方)
return;
}
for (int i = 0; fscanf(fp, "%s %s ", stu[i].num, stu[i].name) != EOF; i++, n++);
cleardevice();
BeginBatchDraw();//缓冲作用 开始绘制UI 不显示
putimage(0, 0, &backTmg);
setbkmode(TRANSPARENT);
setcolor(BLUE);
settextstyle(50, 0, _T("华康少女文字W5(p)"));
outtextxy(200, 40, _T("录 入 学 生"));
EndBatchDraw();//结束绘制 把之前所有内容显示出来
int flag = 1;
for (int i = 100; i < 420; i += 32,flag = -flag) {//色彩变换
if (flag==1)
setfillcolor(RGB(1, 124, 235));
else
setfillcolor(RGB(255, 255, 255));
fillrectangle(60, i, 580, i+32);
}
setcolor(RED);
settextstyle(26, 0, _T("华康少女文字W5(p)"));
outtextxy(65, 105, _T("请输入学号:"));
char ch;
int x = 225,i=0;
while ((ch=getch())!=VK_RETURN) {//输入不等于回车时,文字位移
outtextxy(x, 105,ch);
*(stu[n].num + 1) = ch;
x += 18;
i++;
}
outtextxy(65, 136, _T("请输入姓名:"));
x = 225;
while ((ch = getch()) != VK_RETURN) {
outtextxy(x, 137, ch);
x += 18;
}
fprintf(fp, "%s %s ", stu[n].num, stu[n].name);//这里是保存数据(问题可能的地方)
n++;
fclose(fp);
outtextxy(220, 390, _T("正在保存...."));
Sleep(1000);
}
文件后缀 *.cpp
编译环境 vs2015 多字节字符集
麻烦各位了
