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

Time:01-07

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


Revise ();

return 0;
}
Void revise ()
{
int i;
Password2 char name2 [7], [7], id2 [20].
Char name3 [7].
Printf (" please input to modify the user name: \ n ");
The scanf (" % s ", name3);
Printf (" please enter the user name change: \ n ");
The scanf (" % s ", name2);
Printf (" please enter a password change: \ n ");
The scanf (" % s ", password2);
Printf (" please enter modify id: \ n ");
The scanf (" % s ", id2);
The FILE * fp.
Fp=fopen (" user information. TXT ", "a");

for(i=0; i<5; I++)
{
If (STRCMP (users [I]. Name, name3 [7])==0)
{
Fscanf (fp, "% s % s % s", the users [I]. Name, users [I] password, users [I] id);
Printf (" user name: % s \ n ", the users [I] name);
Printf (" password: % s \ n ", the users [I] password);
Printf (" id: % s \ n ", the users [I] id);
}
break;
}

I -;

Strcpy (users [I]. Name, name2);
Strcpy (users [I]. Password, password2);
Strcpy (users [I]. Id, id2);
Fprintf (fp, "% s % s % s", name2 [7], password2 [7], id2 [7]);
//fputs (name2 [7], fp);
//fputs (password2 [7], fp);
//fputs (id2 [20], fp);
Printf (" modify success!" );
The fclose (fp);
}

CodePudding user response:

For runs only once after the break out,
The fprintf name2 [7] and the back of the several array is wrong, should use the array name, had deleted [7].

CodePudding user response:

reference 1/f, rogue response:
for runs only once after the break out,
The fprintf name2 [7] and the back of the several array is wrong, should use the array name, had deleted [7],

Thank you, but changed after the file content didn't change

CodePudding user response:

Since the original poster is eager to implement file access, that other errors will not mention,
File open to detect failure, another
File cannot be read write
Even if the way you open with a plus sign
Read write operation must also have positioning operation, between for text, rewind it
That is to say, if you don't want to open two
Open it with a plus sign
All read
Rewind
All written
Shut down
In conclusion, it,

CodePudding user response:

Fp=fopen (" user information. TXT ", "a"); This is read and write files, files with fp=fopen (" user information. TXT ", "w");
  • Related