Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct profile
  6. {
  7.     char *username;
  8.     char *password;
  9.    
  10. } PROFILE;
  11.  
  12.  
  13. int main()
  14. {
  15.     load_profile();
  16. }
  17.  
  18. int load_profile(void)
  19. {
  20.     PROFILE p;
  21.     FILE *fp;
  22.     char fd[256];
  23.     char result[256][32];
  24.    
  25.     if((fp = fopen("../data/profile.db","r"))==NULL)
  26.     {
  27.         printf("Cannot open file!\n");
  28.         fclose(fp);
  29.         exit(1);
  30.     }
  31.     else
  32.     {
  33.         while(fgets(fd,sizeof(fd),fp))
  34.         {
  35.             //printf("%s",fd);
  36.         }
  37.         fclose(fp);
  38.     }
  39.    
  40.     split(fd,result);
  41.     printf("The profile.db was successfully retrieved\n");
  42.    
  43.     p.username = result[0];
  44.     p.password = result[1];
  45. }
  46.  
  47. int split(char *str, char splitstr[][32])
  48. {
  49.     char *p;
  50.     p = strtok(str,",");
  51.     int i=0;
  52.    
  53.     while(p)
  54.     {
  55.         strcpy(splitstr[i++],p);
  56.         p = strtok(NULL,",");
  57.     }
  58.     return i;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement