Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Blu-Ray on 12/8/2019.
- //
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<stdlib.h>
- #include "functions.h"
- void getNumOfLines(FILE * f){
- char c;
- for (c = getc(f); c != EOF; c = getc(f)) {
- if (c == '\n')
- count = count + 1;
- }
- count++;
- }
- DateOfBirth *BirthdayConstructor(char* s)
- {
- DateOfBirth *birthday = malloc(sizeof(DateOfBirth));
- int i = 0;
- char *p = strtok(s,"/'\'- ");
- while(p)
- {
- if (i == 0) {
- strcpy(birthday->day, p);
- }
- else if (i == 1) {
- strcpy(birthday->month, p);
- }
- else if (i == 2) {
- strcpy(birthday->year, p);
- }
- p = strtok(NULL,"/'\'- ");
- i++;
- }
- return birthday;
- }
- Contact *saveToStruct(char* str){
- Contact *res = malloc(sizeof(Contact));
- int flag = 0;
- char *token = strtok(str, ",");
- DateOfBirth *bd;
- while( token != NULL )
- {
- if (flag == 0)
- strcpy(res->lastName, token);
- else if (flag == 1)
- strcpy(res->firstName, token);
- else if(flag == 2) {
- bd = BirthdayConstructor(token);
- res->dateOfBirth = *bd;
- }
- else if(flag == 3)
- strcpy(res->stName,token);
- else if(flag == 4)
- strcpy(res->email,token);
- else if(flag == 5)
- strcpy(res->phoneNum,token);
- flag++;
- token = strtok( NULL, "," );
- }
- return res;
- }
- void load(){
- system("cls");
- Contact *c;
- char fileName[] = "hai.txt";
- // printf("Enter file name: ");
- // scanf("%s",fileName);
- FILE *f;
- f = fopen(fileName,"r");
- if(f==NULL) {printf("File doesn't exist\n"); getch();
- return;}
- getNumOfLines(f);
- printf("%s\n",f->_base);
- char* token = strtok(f->_base,"\n");
- printf("%s\n",token);
- Contact *p ;
- p=saveToStruct(token);
- arrCon[0] = *p;
- printf("%s\n",arrCon->phoneNum);
- fclose(f);
- printf("Press any key to continue ..");
- getch();
- }
- void saveFile(){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement