Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. //#include "utils.h"
  4.  
  5. enum entry_type_t { FLOAT, INTEGER};
  6. enum direction_t {ASC, DESC};
  7.  
  8. struct item_t
  9. {
  10. enum entry_type_t type;
  11. union
  12. {
  13. int i;
  14. float f;
  15. };
  16. };
  17.  
  18. struct array_t
  19. {
  20. int size;
  21. struct item_t data[100];
  22. };
  23.  
  24. int read_file(const char* fname, struct array_t *arr)
  25. {
  26. if(!fname || !arr) return 1;
  27.  
  28. FILE *file1;
  29. file1=fopen(fname, "r");
  30. if(!file1) return 2;
  31. enum entry_type_t type;
  32. /*char T[4], *tab=T;
  33. tab=(char *) malloc (sizeof(char)*4);*/
  34. char tab[3];
  35. float x;
  36. int i=0, y;
  37. fscanf(file1, "%s", tab);
  38. if(tab=="INT")
  39. {
  40. fscanf(file1, "%d", &y);
  41. type=INTEGER;
  42. arr->data->i=y;
  43. }
  44. if(tab=="FLO")
  45. {
  46. fscanf(file1, "%f", &x);
  47. type=FLOAT;
  48. arr->*(data+i).
  49. }
  50.  
  51.  
  52.  
  53. //fscanf(file1, "%s", tab3);
  54. //printf("%s\n %d\n %s\n ", tab, y, tab3);
  55. printf("%s\n%d\n", tab, y);
  56.  
  57. return 0;
  58. }
  59.  
  60.  
  61.  
  62. int main()
  63. {
  64. struct array_t *x;
  65. x=(struct array_t *) malloc (sizeof(struct array_t));
  66. read_file("input.txt", x);
  67.  
  68. /*float a=12.5;
  69. int b=1;
  70.  
  71. b=a;
  72.  
  73. printf("%d", b);*/
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement