Home > Back-end >  C ask bosses
C ask bosses

Time:09-21

A c programming practice, didn't find where is wrong
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
reference 1/f, Simple, Soft reply:
what's wrong?

9 6 D: \ using file \ Dvp - Cpp lab assignments \ \ school file 1. C [Warning] the assignment top service pointer from integer without a cast

CodePudding user response:

If ((fp=fopen (" data. TXT ", "w +"))==NULL)
A few braces

CodePudding user response:

reference 3 floor is Simple - Soft reply:
if ((fp=fopen (" data. TXT ", "w +"))==NULL)
Few brackets

Thank you for your guidance, solved
  • Related