Home > Back-end >  | C language compiled, but pass the test set, you should read a bit of a problem is the file
| C language compiled, but pass the test set, you should read a bit of a problem is the file

Time:10-06

 status SaveList (SqList L, char FileName []) 
//if the linear table L exists, the linear table L elements to FileName file, return OK, otherwise returns INFEASIBLE,
{
//please add code here, complete level task
/* * * * * * * * * * the Begin * * * * * * * * */
if(! L.e lem) return INFEASIBLE.
The else
{
The FILE * fp.
If ((fp=fopen (FileName, wb + ""))==NULL)
Return the ERROR;
for(int i=0; i Fprintf (fp, "% d", L.e lem [I]);
The fclose (fp);
return OK;
}

/* * * * * * * * * * End * * * * * * * * * */
}
The status LoadList (SqList & amp; L, char FileName [])
//if the linear table does not exist, L read data from the FileName file into the linear table L, return OK, otherwise returns INFEASIBLE,
{
//please add code here, complete level task
/* * * * * * * * * * the Begin * * * * * * * * */
if(! L.e lem)
{
L.l ength=0;
The FILE * fp1;
If ((fp1=fopen (FileName, "r"))==NULL)
Return the ERROR;
While (fread (& amp; L.e lem [L.l ength], sizeof (ElemType), 1, fp1))
L.l ength++;
The fclose (fp1);
return OK;
}
The else return INFEASIBLE.
/* * * * * * * * * * End * * * * * * * * * */
}


Platform automatically read input data, for you to write code to test, and the output,

Test inputs: 0; Said at this time to write file doesn't exist linear table operations, or read the file data overwrite existing linear table cause data loss,
The expected output:
INFEASIBLE

11 12 13 14 15 test inputs: 1 0, the first number 1 to an existing linear table, follow-up is a zero sequence data element, the end of the
The expected output:
5
11 12 13 14 15
Just when input the second test set nothing output
This is the main function
 # include "def. H" 
# include "string. H"

# include "stu. H"
Int main ()
{
SqList L;
The FILE * fp.
Char FileName [30].
Int f, I=0, j, e;
Strcpy (FileName, "SRC/step13/list. Dat");
The scanf (" % d ", & amp; f);
if (! F)
{
L.e lem=NULL;
J=SaveList (L, FileName);
If (j!=INFEASIBLE) printf (" can't write files on linear table does not exist for operation!" );
The else
{
L.e lem=(ElemType *) malloc (sizeof (ElemType));
J=LoadList (L, FileName);
If (j!=INFEASIBLE) printf (" can't read the file on the existing linear table for operation!" );
The else printf (" INFEASIBLE ");
Free (L.e lem);
}
}
The else
{
L.e lem=(ElemType *) malloc (sizeof (ElemType) * LIST_INIT_SIZE);
L.length=0;
L.l istsize=LIST_INIT_SIZE;
The scanf (" % d ", & amp; e);
While (e)
{
L.e lem [i++]=e;
The scanf (" % d ", & amp; e);
}
L.l ength=I;
J=SaveList (L, FileName);
Free (L.e lem);
L.e lem=NULL;
J=LoadList (L, FileName);
Printf (" % d \ n ", L.l ength);
for(i=0; iPrintf (" % d ", L.e lem [I]);
}
return 1;
}
  • Related