最近编了个背单词用的程序
添加词库功能一切正常
[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]
编译通过了,但输出时显示乱码 |