Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Record get_rec_file(FILE *file) {
- // FILE *file;
- Record rec;
- //rec=malloc(sizeof(Record));
- int len,id,c1,x;
- char str_id[15];
- char buffer[150],name[15],c;
- char surname[20];
- char address[40];
- // file = fopen("records1K.txt", "r");
- /*
- if( file == NULL ) {
- perror ("Error opening file");
- return(-1);
- }
- */
- int i=0;
- while((c = fgetc(file)) != '}' && i<150){
- buffer[i]=c;
- i++;
- }
- x=1;
- c1=0;
- while(buffer[x]!= ','){
- if(buffer[x]!='{'){
- str_id[c1]=buffer[x];
- c1++;
- x++;}
- else
- x++;
- }
- str_id[c1]='\0';
- x++;
- c1=0;
- while(buffer[x]!= ','){
- rec.name[c1]=buffer[x];
- c1++;
- x++;
- }
- rec.name[c1]='\0';
- x++;
- c1=0;
- while(buffer[x]!= ','){
- rec.surname[c1]=buffer[x];
- c1++;
- x++;
- }
- rec.surname[c1]='\0';
- x++;
- c1=0;
- while(buffer[x]!= '\0'){
- rec.address[c1]=buffer[x];
- c1++;
- x++;
- }
- rec.address[c1]='\0';
- rec.id=atoi(str_id);
- printf(" %d \n",rec.id);
- // printf(" %s \n",str_id);
- printf(" %s \n",rec.name);
- printf(" %s \n",rec.surname);
- printf(" %s \n",rec.address);
- printf(" dfsdfs\n ");
- return rec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement