c语言:简单英文词典排版系统,代码可以运行但有错误
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define ROWS 258
#define COLS 32
#define N 1000
static FILE *fp;
static char a[ROWS][COLS];
char get_optioin(viod);
int b(int count);
void c(char pt[],int count);
int check(char arr[],int count);
void storage(char pt[],int count);
int n;
char word[N][20];
void menu()
{
int n,w;
do
{
puts("\tMENU\n");
puts("\t1.Add new word");
puts("\t2.Browse all the words");
puts("\t3.Search the word");
puts("\t4.Sort the words");
puts("\t5.Order by A-Z");
puts("\t6.Exit");
puts("*\n");
printf("Choice your number(1-6):[ ]\b\b");
scanf("%d",&n);
if(n<1||n>6)
{
w=1;
getchar();
}
else w=0;
}while(w==1);
switch(n)
{
case 1:add();break;
case 2:browse();break;
case 3:search();break;
case 4:sort();break;
case 5:order();break;
case 6:exit(0);
}
}
void main(){
menu();
}
int load()
{
int i,count;
int start;
char *pt[ROWS];
char ch,len;
char input;
if((fp=fopen("words.txt","a+"))==NULL)
{
printf("\ncannot open file!\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fscanf(fp,"%s",&word[i]);
fclose(fp);
return i+1;
}
void save(int n)
{
FILE *fp;
int i;
if((fp=fopen("words.txt","a+"))==NULL)
{
printf("\ncannot open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fprintf(fp,"%s",&word[i]);
fclose(fp);
}
void sort()
{
int i,j,k;
char c[20];
if((n=load())==0)
{
printf("\n cannot open file!\n");
exit(0);
}
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++);
if(strcmp(word[j],word[j+1])>0)
{
strcmp(c,word[j]);
strcmp(word[j],word[j+1]);
strcmp(word[j+1],c);
}
save(n);
printf("successful!\n");
printf("\nNow? 1.browse all 2.back");
scanf("%d",&k);
if(k==1)
browse();
else if(k==2)
menu();
}
void order()
{
int a[N],i,j,t;
struct words;
n=load();
for(i=0;i<N;i++)
for(i=0;i<N-1;i++)
for(j=i+i;j<N;j++)
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
for(j=0;j<N;j++)
printf("%3d",a[i]);
}
void modify(int a)
{
char c[20];
printf("Enter the new word:");
scanf("%s",c);
strcpy(word[a],c);
save(n);
}
void del(int a)
{
int x,i,y;
printf("are you sure to delate this word?\n\t1.sure 2.no and back menu []\b\b");
scanf("%d",&x);
if(x==1)
{
for(i=0;i<n-1;i++)
strcpy(word[i],word[i+1]);
save(n-1);
printf("successful! now? 1.one more 2.back menu");
scanf("%d",&y);
if(y==1)
search();
else if(y==2)
menu();
}
else if(x==2)
{
menu();
}
}
void add()
{
int i,x,u,v,w;
char c[20];
if((n=load())==0)
exit(0);
else
{
puts("Enter the new word!\n");
scanf("%s",c);
for(i=0;i<n;i++)
{
if(strcmp(word[i],c)==0)
break;
}
if(i<n)
{
w=1;
do
{
printf("the word has already exit!\n");
printf("\n\nwhat do you want to do?\n\t1.enter one more 2.back menu []\b\b");
scanf("%d",&x);
if(x<1||x>2)
u=1;
else
u=0;
}while(u==1);
}
else
{
v=1;
strcpy(word[i],c);
save(n+1);
printf("successful! now choice what you will do next?\n\t1.add another 2.back menu [ ]\b\b");
do
{
scanf("%d",&x);
if(x<1||x>2)
v=1;
else
v=0;
}while(v==1);
}
switch(x)
{
case 1:add();break;
case 2:menu();break;
}
}
}
void browse()
{
int i,w;
if((n=load())==0)
{
printf("\n cannot open file\n");
exit(0);
}
for(i=0;i<n-1;i++)
printf("%s/n",word[i]);
puts("successful! now 1.back menu 2.sort");
scanf("%d",&w);
if(w==1)
menu();
else if(w==2)
sort();
}
void search()
{
int i,x,y;
char vs[20];
if((n=load())==0)
{
printf("\n cannot open file\n");
exit(0);
}
printf("Enter the word what you want to search:\n");
scanf("%s",vs);
for(i=0;i<n;i++)
if(strcmp(word[i],vs)==0)
{
printf("successful!\n the word is %s\n",word[i]);
printf("what would you like to do with the word?\n\t 1.modify 2.delrte 3.nothing []\b\b");
scanf("%d",&y);
if(y==1)
modify(i);
else{del(i);}
}
if(i==n)
printf("hoho!sorry.not found~");
printf("now.1.one more 2.back 3exit");
scanf("%d",&x);
switch(x)
{
case 1:search();break;
case 2:menu();break;
case 3:exit(0);
}
}
可以运行但结果错误
有能解释一下原理和帮忙修改一下吗?谢谢。