Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct profile
- {
- char *username;
- char *password;
- } PROFILE;
- int main()
- {
- load_profile();
- }
- int load_profile(void)
- {
- PROFILE p;
- FILE *fp;
- char fd[256];
- char result[256][32];
- if((fp = fopen("../data/profile.db","r"))==NULL)
- {
- printf("Cannot open file!\n");
- fclose(fp);
- exit(1);
- }
- else
- {
- while(fgets(fd,sizeof(fd),fp))
- {
- //printf("%s",fd);
- }
- fclose(fp);
- }
- split(fd,result);
- printf("The profile.db was successfully retrieved\n");
- p.username = result[0];
- p.password = result[1];
- }
- int split(char *str, char splitstr[][32])
- {
- char *p;
- p = strtok(str,",");
- int i=0;
- while(p)
- {
- strcpy(splitstr[i++],p);
- p = strtok(NULL,",");
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement