搜索
查看: 1445|回复: 5
打印 上一主题 下一主题

问题

[复制链接]
跳转到指定楼层
楼主
发表于 2013-3-24 14:43:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
8啊哈币
最近编了个背单词用的程序
添加词库功能一切正常
[code=Css width=740px]#include <stdio.h>
#include <stdlib.h>
main()
{ struct word
{ char spell[36];
char pos[40];
char mean[100];
int put;
int check;
}word[100];
int n;
for(n=0;n<=1000;n++)
{
FILE *fp1;
fp1=fopen("词库.txt","r");
fread(&word[n],sizeof(struct word),1,fp1);
if(word[n].put)
continue;
else
break;
}
for(n=0;n<=1000;n++)
{
printf("请输入单词:\n");
scanf("%s",word[n].spell);
printf("请输入音标:\n");
scanf("%s",word[n].pos);
printf("请输入词义:\n");
scanf("%s",word[n].mean);
word[n].put=1;
word[n].check=0;

FILE *fp;
fp=fopen("词库.txt","a+");
fwrite(&word[n],sizeof(struct word),1,fp);
int a;
printf("是否结束?(1——是,2——否)\n");
scanf("%d",&a);
if(a-2)
exit(0);
}
system("pause");
return 0;
}
[/code]
但是输出时有问题。
[code=Css width=740px]#include <stdio.h>
#include <stdlib.h>
main()
{ struct word
{ char spell[36];
char pos[40];
char mean[100];
int put;
int check;
}word[100];
int n;
for(n=0;n<=1000;n++)
{
FILE *fp1;
fp1=fopen("词库.txt","r");
fread(&word[n],sizeof(struct word),1,fp1);
if(word[n].put==1)
continue;
else
break;
}
for(n=0;n<=1000;n++)
{
printf("%s",word[n].spell);
printf("%s",word[n].pos);
printf("%s",word[n].mean);
}
system("pause");
return 0;
}
[/code]
编译通过了,但输出时显示乱码

沙发
 楼主| 发表于 2013-3-24 14:47:53 | 只看该作者
for(n=0;n<=1000;n++)
是1000

for(n=0;n<=1000;n++)
是100的原因是电脑太破,内存8够
板凳
发表于 2013-3-27 19:46:13 | 只看该作者
存单词的那个文件,你试试存几个,然后用写字板打开看看不是乱码,我觉得应该是存入单词的时候就有问题。
地板
 楼主| 发表于 2013-3-31 12:49:51 | 只看该作者
zynpc 发表于 2013-3-27 19:46
存单词的那个文件,你试试存几个,然后用写字板打开看看不是乱码,我觉得应该是存入单词的时候就有问题。

存入单词的时没有问题
5#
 楼主| 发表于 2013-3-31 12:52:45 | 只看该作者
用记事本看本来就该是乱码,fwrite和fread读写文件时是以2进制方式进行的
6#
发表于 2015-8-17 15:40:50 | 只看该作者
呵呵
{:soso_e176:}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表