Home > Back-end >  A about english-chinese electronic dictionary, leaders help me to look at the trouble, solve the pro
A about english-chinese electronic dictionary, leaders help me to look at the trouble, solve the pro

Time:09-17

#include
#include
Int worsNumber=0;
Typedef struct dic
{
Char word [20];
Char cn [80];
} the data;
Data dictionarySql [9000].

Int loadSql (SQL data * and char path [100])
{
int i=0;
The FILE * fp=NULL;
Fp=fopen (" dictionary. TXT ", "r");
While (fscanf (fp, "% s" \ t % s, SQL + (I) - & gt; Word, (SQL + I) - & gt; Cn)!=(EOF)
{
i++;
}
The fclose (fp);
Printf (" a total of % d word data \ n ", I);
Printf (" word loading is completed, please enter the command to operate: \ n ");
Return (I);
}

Void printAction ()
{
Printf (" * * * * * * * * * * * * * * * * * you are welcome to use the electronic dictionary! * * * * * * * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * * * * * * direct input to query words can * * * * * * * * * * * * \ n \ n \ n ");
Printf (" 1. English-chinese \ t | \ n ");
Printf (" | 2. In chinese-english translation \ t \ n ");
Printf (" 3. Add the word data \ t | \ n ");
Printf (" 4. Delete the word data \ t | \ n ");
Printf (" | 5. Correct word \ t \ n ");
Printf (" | 0. Quit \ t \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
}

Void dealAction (int action)
{
If (action==1)
{
Char word [20];
Int pos.
Printf (" please input the words to query: ");
The scanf (" % s ", the word);
Pos=searchWord (word);
If (pos!=1)
Printf (" word \ '% s \' in Chinese means: % s \ n ", the word, dictionarySql [pos]. Cn);
The else
Printf (" I'm sorry, didn't find what you need word \ n ");
}
Else if (action==2)
{
Int pos.
Char cn [80];
Printf (" please input Chinese meaning: ");
The scanf (" % s ", cn);
Pos=searchCn (cn);
If (pos!=1)
Printf (" the translation of English words is: % s \ n ", dictionarySql (pos). The word);
The else
Printf (" I'm sorry, didn't find what you need word \ n ");
}
Else if (action==3)
{
Char word [20];
Char cn [80];
Printf (" please input you want to add the words: ");
The scanf (" % s ", the word);
Strcpy (dictionarySql [worsNumber]. Word, word);
Printf (" please input the word Chinese translation: ");
The scanf (" % s ", cn);
Strcpy (dictionarySql [worsNumber]. Cn, cn);
WorsNumber++;
SaveSql ();
Printf (" supplementary words to complete the \ n ");

}
Else if (action==4)
{
Char word [50];
Int pos.
Printf (" please input you want to delete the words: ");
The scanf (" % s ", the word);
Pos=searchWord (word);
If (pos!=1)
{
Char a, [5]="#".
Strcpy (dictionarySql [pos]. Cn, a);
Strcpy (dictionarySql (pos). The word, a);
SaveSql ();
Printf (" has been deleted the word \ n ");
}
The else
Printf (" I'm sorry, didn't find what you need word \ n ");
}
Else if (action==5)
{
Char word [50];
Int pos.
Printf (" please enter your correct word: ");
The scanf (" % s ", the word);
Pos=searchWord (word);
If (pos!=1)
{
Printf (" please enter the word Chinese translation: ");
Char cn [60];
The scanf (" % s ", cn);
Strcpy (dictionarySql [pos]. Cn, cn);
SaveSql ();
Printf (" has fixed the word translation, \ n ");
}
The else
Printf (" I'm sorry, didn't find what you need word \ n ");

}
}
Int searchWord (char word [20])
{
Int low, mid, high;
Low=0;
High=worsNumber;
While (low<=high)
{
Mid=+ high (low)/2;
If (STRCMP (dictionarySql [mid]. Word, word) & gt; 0)
High=mid - 1;
Else if (STRCMP (dictionarySql [mid]. Word, word) & lt; 0)
Low=mid + 1;
The else
{
Return mid;
}
}

int i=0;
for(i=0; i{
If (STRCMP (dictionarySql [I]. Word, word)==0)
return i;
}
return -1;
}
Int searchCn (char cn [80])
{
int i=0;
for(i=0; i{
If (STRSTR (dictionarySql [I]. Cn, cn)!=NULL)
return i;
}
return -1;
}
Void saveSql ()
{
The FILE * fp=NULL;
Fp=fopen (" dictionary. TXT ", "w");
int i=0;
for(i=0; i{
If (dictionarySql [I]. Word [0]!='#')
{

Fprintf (fp, "% s \ n \ t % s", dictionarySql [I] word, dictionarySql [I]. Cn);
}
}
The fclose (fp);
}


Int main ()
{
WorsNumber=loadSql (dictionarySql, "dictionary. TXT");
Int action=1;
While (the action!=0)
{
PrintAction ();
The scanf (" % d ", & amp; The action);
DealAction (action);
}
return 0;
}
1. The CPP (47) : error C2065: 'searchWord' : undeclared identifier
2. The CPP (59) : error C2065: 'searchCn: undeclared identifier
3. The CPP (76) : error C2065: 'saveSql: undeclared identifier
4. CPP (120) : error C2373: 'searchWord' : redefinition; The company type modifiers
5. The CPP (146) : error C2373: 'searchCn: redefinition. The company type modifiers
6. CPP (156) : error C2373: 'saveSql: redefinition; The company type modifiers

CodePudding user response:

 int loadSql (SQL data * and char path [100]). 
Void printAction ();
Void dealAction (int action);
Int searchWord (char word [20]);
Int searchCn (char cn [80]);
Void saveSql ();

Please explain in the front of the program and function, this compilation warning error,

CodePudding user response:

 int loadSql (data *, char []); 
Void printAction (void);
Void dealAction (int);
Int searchWord (char []);
Int searchCn (char []);
Void saveSql (void);

The function description is more general,
  • Related