Home > Back-end >  Why didn't the contents of the file change?
Why didn't the contents of the file change?

Time:01-07

#include
#include
#include
#include
#include
Struct yonghu//user information
{
Int zhanghao;//account
Char name [7];//user name
Char id [20];//user id
Char password [10].//the user password
} the users [500];
Void revise ();//modify information
Int main ()
{


Revise ();

return 0;
}
Void revise ()
{
int i;
Int zhanghao2;
Password2 char name2 [7], [10], id2 [20].
Char name3 [7].
Printf (" please input to modify the user name: \ n ");
The scanf (" % s ", name3);
Printf (" please enter the modify account: \ n ");
The scanf (" % d ", & amp; Zhanghao2);
Printf (" please enter the user name change: \ n ");
The scanf (" % s ", name2);
Printf (" please enter modify id: \ n ");
The scanf (" % s ", id2);
Printf (" please enter a password change: \ n ");
The scanf (" % s ", password2);

The FILE * fp.
Fp=fopen (" user information. TXT ", "r +");
If (fp==NULL)
{
Printf (" error file can 't be open! \n");
exit(0);
}


for(i=0;; I++)
{
Fscanf (fp, "% d % s % s % s", & amp; The users [I]. Zhanghao, users [I]. Name, users [I] id, users [I], ");
If (STRCMP (users [I]. Name, name3 [7])==0)
{
//printf (" 2 ");
The users [I] zhanghao=zhanghao2;
Strcpy (users [I]. Name, name2 [7]);
Strcpy (users [I]. Id, id2 [20]);
Strcpy (users [I]. Password, password2 [10]);

Fprintf (fp, "% d % s % s % s", the users [I] zhanghao, users [I]. Name, users [I] id, users [I], ");
}


}
The fclose (fp);
Printf (" modify success!" );
}
  • Related