Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 1024
  3.  
  4. void alloc(char** s);
  5. void matrixFree(char** s, int count);
  6. void textToMas(char** s, int& count, FILE* f1);
  7. void textInput(char** s, int count, FILE* f2);
  8.  
  9. int main()
  10. {
  11. char** s = new char* [N];
  12. alloc(s);
  13. FILE* f1 = fopen("original.txt", "r");
  14. FILE* f2 = fopen("edited.txt", "w");
  15. int count = 0;
  16.  
  17. textToMas(s, count, f1);
  18. textInput(s, count, f2);
  19.  
  20. matrixFree(s, count);
  21. fclose(f1);
  22. fclose(f2);
  23. return 0;
  24. }
  25.  
  26. void alloc(char** s)
  27. {
  28. for (int i = 0; i < N; i++)
  29. s[i] = new char[N];
  30. }
  31.  
  32. void matrixFree(char** s, int count)
  33. {
  34. for (int i = 0; i < N; i++)
  35. delete[] s[i];
  36. delete[] s;
  37. }
  38.  
  39. void textInput(char** s, int count, FILE* f2)
  40. {
  41. int j = 1;
  42. for (int i = 0; i < count; i++)
  43. {
  44. if (s[i][0] == '\n') continue;
  45. else
  46. {
  47. fprintf(f2, "%d.", j);
  48. j++;
  49. fputs(s[i], f2);
  50. }
  51. }
  52. }
  53.  
  54. void textToMas(char** s, int& count, FILE* f1)
  55. {
  56. for (int i = 0; !feof(f1); i++)
  57. {
  58. if (i == N)
  59. {
  60. count--;
  61. break;
  62. }
  63. fgets(s[i], N, f1);
  64. count++;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement