Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. void pw_tofile(char * login, char * new_password){
  2.     FILE *fp;
  3.     FILE *new_file;
  4.  
  5.     char line[MAX_PASSWORD];
  6.  
  7.     if ((fp = fopen("client.aut.txt","r")) == NULL){
  8.         printf("File missing\n");
  9.         exit(0);
  10.     }
  11.     new_file = fopen("new_aut.txt","w");
  12.  
  13.     while(!feof(fp)){
  14.         //reads a login so MAX_LOGIN
  15.         fgets(line,MAX_LOGIN,fp);
  16.         printf("user: %s",line);
  17.         fputs(line,new_file);      
  18.         if ((strncmp(login,line,strlen(login))) == 0){
  19.             printf("Encontered client\n");
  20.             //skips old password
  21.             fgets(line,MAX_PASSWORD,fp);           
  22.             printf("password: %s",line);           
  23.             //writes new password to new file
  24.             fputs(new_password,new_file);
  25.             fputs("\n",new_file);
  26.         }
  27.         else{
  28.             //reads password and writes to new file
  29.             fgets(line,MAX_PASSWORD,fp);
  30.             printf("password: %s",line);           
  31.             fputs(line,new_file);
  32.         }  
  33.         //reads aut and writes to new file     
  34.         fgets(line,MAX_LOGIN,fp);  
  35.         printf("aut: %s",line);
  36.         fputs(line,new_file);      
  37.     }
  38.  
  39.     /*if((rename("new_aut.txt","client.aut.txt")) == -1){
  40.         printf("Error renaming new file");
  41.     }*/
  42.  
  43.     fclose(fp);
  44.     fclose(new_file);
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement