fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define FILE_NAME "Input.txt"
  5. #define FILE_MOD "r"
  6. #define BUFFER_SIZE 255
  7.  
  8.  
  9. int main()
  10. {
  11. FILE *infile = stdin;//fopen(FILE_NAME,FILE_MOD);
  12. if (infile == NULL)
  13. {
  14. printf("Error\n");
  15. return 0;
  16. }
  17.  
  18. char buff[BUFFER_SIZE];
  19.  
  20.  
  21. while (!feof(infile))
  22. {
  23. char *tmp = NULL;
  24. int iTotalLen = 0;
  25.  
  26. while (1)
  27. {
  28. fgets(buff,BUFFER_SIZE,infile);
  29. int len = strlen(buff);
  30. printf("len = %d\n",len);
  31.  
  32. tmp = (char*)realloc(tmp, len + iTotalLen);
  33.  
  34. strcpy(tmp + iTotalLen, buff);
  35.  
  36. iTotalLen += len;
  37.  
  38. if (len < 255) break;
  39.  
  40. }
  41. printf(tmp);
  42.  
  43. free( tmp);// ось тут проблема
  44. }
  45.  
  46. fclose(infile);
  47. }
Success #stdin #stdout 0s 2288KB
stdin
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
kldfhsdklfhgshsdglhsldfhl
stdout
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl
len = 26
kldfhsdklfhgshsdglhsldfhl