Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void pw_tofile(char * login, char * new_password){
- FILE *fp;
- FILE *new_file;
- char line[MAX_PASSWORD];
- if ((fp = fopen("client.aut.txt","r")) == NULL){
- printf("File missing\n");
- exit(0);
- }
- new_file = fopen("new_aut.txt","w");
- while(!feof(fp)){
- //reads a login so MAX_LOGIN
- fgets(line,MAX_LOGIN,fp);
- printf("user: %s",line);
- fputs(line,new_file);
- if ((strncmp(login,line,strlen(login))) == 0){
- printf("Encontered client\n");
- //skips old password
- fgets(line,MAX_PASSWORD,fp);
- printf("password: %s",line);
- //writes new password to new file
- fputs(new_password,new_file);
- fputs("\n",new_file);
- }
- else{
- //reads password and writes to new file
- fgets(line,MAX_PASSWORD,fp);
- printf("password: %s",line);
- fputs(line,new_file);
- }
- //reads aut and writes to new file
- fgets(line,MAX_LOGIN,fp);
- printf("aut: %s",line);
- fputs(line,new_file);
- }
- /*if((rename("new_aut.txt","client.aut.txt")) == -1){
- printf("Error renaming new file");
- }*/
- fclose(fp);
- fclose(new_file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement