Keyboard entry name, deposited in the file data. TXT, this name already exists, if the file is displayed file corresponding to the existing information, enter a different name again; If there is no the file name, it is in the file,
# include
# include & lt; String. H>
# include & lt; Stdlib. H>
Int main (void)
{
The FILE * fp.
Int flag=0;
Char name [20], data [20].
If (fp=fopen (" data. TXT ", "w +")==NULL)
{
Printf (" Can 't open the file!" );
exit(1);
}
Do
{
Printf (" both Please input the name: ");
Gets (name);
If (strlen (name)==0)
break;
The else strcat (name, "\ n");
The rewind (fp);
flag=1;
While (flag& & ((the fgets (data, 20, fp)!=NULL)))
If (STRCMP (data, name)==0)
flag=0;
If (flag)
The fputs (name, fp);
The else
Printf (" \ tThis name existed! \n");
} while (ferror (fp)==0).
The fclose (fp);
Return 0;
}
CodePudding user response:
What's wrong?CodePudding user response:
The