Home > OS >  Have a great god can see what is going wrong? Every time is such, have been a blow to my confidence.
Have a great god can see what is going wrong? Every time is such, have been a blow to my confidence.

Time:11-05

#include
#include
#include
#include
#include
# define CODE 0 x3b
# define MAXLEN 100
Typedef struct
{
Char * English;
Char * Chinese;
} Word;
Word Word [MAXLEN];
Int testType=0;
Int the init ()
{
The FILE * fp.
Char fname [50].
Char line [MAXLEN];
Char * p;
Char * word1;
Char * word2.
int i=0;
Int j=0;
Int len.
Printf (" \ t welcome to the words the test stuition \ n ");
Printf ("============================================\ n ");
Printf (" do input the fname: ");
The scanf (" % s ", fname);
If ((fp=fopen (fname, "r"))==NULL)
{
Printf (" the opened the error ");
The exit (0);
}
The fflush (stdin);
While (the fgets (line, MAXLEN, fp))
{
for(j=0; j{
If (line [j]. )
='\ n'{
Line [j]=line [j] ^ CODE;
}
}
P=STRCHR (line, '\ n');
If (p!=NULL)
{
* p='\ 0';
}
P=STRCHR (line, '=');
Word1=line;
Word2=p;
* p='\ 0';
+ + word2.
Len=strlen (word1);
Word [I]. English=(char *) malloc (len + 1);
Strcpy (word [I]. English, word1);
Len=strlen (word2);
The word [I]. Chinese=(char *) malloc (len + 1);
Strcpy (word [I]. Chinese, word2);
i++;
}
The fclose (fp);
return i;
}
Void endtest (int size)
{
int i;
for(i=0; i{
Free (word [I]. English);
The word [I]. English=NULL;
Free (word [I]. Chinese);
The word [I]. Chinese=NULL;
}
}
Void test (int size)
{
Int I, j, t;
int flag;
Char choice;
Int xm [4];
int count=0;
int score=0;
Printf (" do choice; 1 - Chinese to eng0 - eng to chin ");
The scanf (" % d ", & amp; TestType);
The fflush (stdin);

for(i=0; i{
if(! TestType)
{
Printf (" % d.e nglish -- means: - % s \ n ", I + 1, word [I] English);
}
The else
{printf (" %, dc hin - % s - means: \ n ", I + 1, word [I]. Chinese);
}
srand(time(NULL));
Count=0;
While (count
=4){
T=rand () % size;
If (t==I)
{
continue;
}
Flag=0;
for(j=0; j{
If (xm [j]==t)
{
Flag=1;
}
}
if(! Flag)
{
Xm [count]=t;
count++;
}
}
T=rand () % 4;
Xm [t]=I;
if(! TestType)
{
Printf (" \ nA. % s \ n ", the word [xm [0]]. Chinese);
Printf (" \ nB. % s \ n ", the word [xm [1]]. Chinese);
Printf (" \ nC % s \ n ", the word [xm [2]]. Chinese);
Printf (" \ nD. % s \ n ", the word [xm [3]]. Chinese);
}
The else
{
Printf (" \ tA. % s \ n ", the word [xm [0]]. English);
Printf (" \ tB. % s \ n ", the word [xm [1]]. English);
Printf (" \ tC. % s \ n ", the word [xm [2]]. English);
Printf (" \ tD. % s \ n ", the word [xm [3]]. English);
}
Printf (" both please input your choice: ");
Choice=getchar ();
The fflush (stdin);
If (choice>='a' & amp; & Choice<='z')
{
Choice=choice - 'a' + 'a';
}
If (choice - 'A'==t)
{
Printf (" sorry, you are wromg ");
Score++;
}
The else
{
Printf (" sorry, you are worng ");
Printf (" the correct answer is: % c. \ n ", 'A' + t);
}
getchar();
}
Printf (" the game is over. Amoutis % d. The correct is % d \ n \ nwelcome next time \ n ", the size, the score).
}
Int main (void)
{
Int size=init ();
The test (size);
getchar();
return 0;
}

CodePudding user response:

P=STRCHR (line, '=');
Word1=line;
Word2=p;
* p='\ 0';

P here is NULL (when not find=), lead to the collapse
  • Related