Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. struct line
  7. {
  8. char *text;
  9. int numar;
  10. };
  11.  
  12. /**
  13. struct line* Read(int *size, FILE* in)
  14. {
  15. struct line* list;
  16. list = NULL;
  17.  
  18. char* text;
  19. int size_text = 0;
  20. int num_contor = 0;
  21.  
  22. int new_word = 1;
  23. int c;
  24. c = fgetc(in);
  25. while(c!=EOF && c != (int) '\n')
  26. {
  27. size_text = 0;
  28. text = NULL;
  29. num_contor = 0;
  30.  
  31. new_word = 1;
  32.  
  33. (*size)++;
  34. //list = (struct line*)realloc(list, (*size) * sizeof(struct line));
  35. while(c != (int) '\n' && c!= EOF)
  36. {
  37. //printf("c");
  38. printf("%d", c);
  39. size_text++;
  40. //text = (char*) realloc(text, (size_text+1)*sizeof(char));
  41.  
  42. if(new_word && isdigit((char)c))
  43. num_contor++;
  44.  
  45. if(isspace((char)c))
  46. new_word = 1;
  47. c = fgetc(in);
  48. }
  49. //list[(*size)-1].text = text;
  50. //list[(*size)-1].numar = num_contor;
  51. }
  52. return list;
  53. }
  54. **/
  55.  
  56. char* Read_Line(FILE *in)
  57. {
  58. //printf("%p\n", in);
  59. char* line;
  60. line = NULL;
  61. line = (char*) realloc(line,sizeof(char));
  62.  
  63. int index = 0;
  64.  
  65. int c;
  66. while((c = fgetc(in)) != '\n')
  67. {
  68. //printf("%c",c);
  69. line = (char*) realloc(line,(index+2)*sizeof(char));
  70. line[index] = (char)c;
  71. index++;
  72. }
  73. line[index] = '\0';
  74. return line;
  75. }
  76. int main(int argc, char* argv[])
  77. {
  78. FILE* in;
  79. in = fopen(argv[0], "r");
  80. //in = fopen("sample.txt", "r");
  81. //printf("%s", argv[1]);
  82. //printf("%p\n", in);
  83. if(in!=NULL)
  84. {
  85. struct line *v;
  86. int size = 0;
  87. v = NULL;
  88. v = (struct line*)realloc(v, sizeof(struct line));
  89.  
  90. char *linie;
  91. linie = Read_Line(in);
  92. printf("%s", linie);
  93. //printf("%s", v[0].text);
  94.  
  95. //v = Read(&size, in);
  96. fclose(in);
  97. //printf("%s", v[0].text);
  98. //printf("%d", size);
  99. }
  100. else
  101. {
  102. printf("Unable to open folder");
  103. }
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement