Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. Record get_rec_file(FILE *file) {
  2. // FILE *file;
  3. Record rec;
  4. //rec=malloc(sizeof(Record));
  5. int len,id,c1,x;
  6. char str_id[15];
  7. char buffer[150],name[15],c;
  8. char surname[20];
  9. char address[40];
  10. // file = fopen("records1K.txt", "r");
  11. /*
  12. if( file == NULL ) {
  13. perror ("Error opening file");
  14. return(-1);
  15. }
  16. */
  17. int i=0;
  18.  
  19. while((c = fgetc(file)) != '}' && i<150){
  20.  
  21. buffer[i]=c;
  22. i++;
  23.  
  24. }
  25.  
  26. x=1;
  27. c1=0;
  28.  
  29. while(buffer[x]!= ','){
  30. if(buffer[x]!='{'){
  31. str_id[c1]=buffer[x];
  32. c1++;
  33. x++;}
  34. else
  35. x++;
  36.  
  37. }
  38. str_id[c1]='\0';
  39. x++;
  40. c1=0;
  41.  
  42. while(buffer[x]!= ','){
  43. rec.name[c1]=buffer[x];
  44. c1++;
  45. x++;
  46. }
  47. rec.name[c1]='\0';
  48. x++;
  49. c1=0;
  50.  
  51. while(buffer[x]!= ','){
  52. rec.surname[c1]=buffer[x];
  53. c1++;
  54. x++;
  55. }
  56. rec.surname[c1]='\0';
  57. x++;
  58. c1=0;
  59.  
  60. while(buffer[x]!= '\0'){
  61. rec.address[c1]=buffer[x];
  62. c1++;
  63. x++;
  64. }
  65. rec.address[c1]='\0';
  66. rec.id=atoi(str_id);
  67. printf(" %d \n",rec.id);
  68. // printf(" %s \n",str_id);
  69. printf(" %s \n",rec.name);
  70. printf(" %s \n",rec.surname);
  71. printf(" %s \n",rec.address);
  72. printf(" dfsdfs\n ");
  73. return rec;
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement