Advertisement
Zennoma

nebanplz

Apr 23rd, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <cstring>
  3. #include "ctime"
  4. #include "math.h"
  5. #include <tchar.h>
  6. #include <cstring>
  7. #include "stdlib.h"
  8. #include <string>
  9. #include "conio.h"
  10. #include <fstream>
  11.  
  12. using namespace std;
  13.  
  14.  
  15. FILE show(FILE* file)
  16. {
  17. rewind(file);
  18. char* string;
  19. string = new char[128];
  20. while (fgets(string, 128, file) > 0)
  21. puts(string);
  22. return(*file);
  23. }
  24. FILE fill(FILE* file)
  25. {
  26. rewind(file);
  27. char* string;
  28. string = new char[128];
  29. while (gets_s(string, 128), strlen(string) != 0)
  30. {
  31. fputs(string, file);
  32. fputs("\n", file);
  33. }
  34. return (*file);
  35. }
  36. FILE* task(FILE* file, FILE* newfile)
  37. {
  38. float sum = 0;
  39. int count = 0;
  40. char name[3];
  41. rewind(file);
  42. char* string;
  43. string = new char[128];
  44. while (fgets(string, 128, file) > 0)
  45. {
  46. char* pch = strtok(string, " ");
  47. fputs(pch, newfile);
  48. fprintf(newfile, " ");
  49. pch = strtok(NULL, " ");
  50. strncpy(name, pch, 1);
  51. name[1] = '.';
  52. name[2] = '\0';
  53. fputs(name, newfile);
  54. fprintf(newfile, " ");
  55. pch = strtok(NULL, " ");
  56. while (pch != NULL)
  57. {
  58. sum += atoi(pch);
  59. count++;
  60. pch = strtok(NULL, " ");
  61. }
  62. sum /= count;
  63. fprintf(newfile, "%4f\n", sum);
  64. count = 0;
  65. sum = 0;
  66. }
  67. return newfile;
  68. }
  69. int main() {
  70. srand(time(NULL));
  71. FILE* file;
  72. FILE* newfile;
  73. char name[] = "my.txt";
  74. char name1[] = "my1.txt";
  75. file = fopen(name, "w+");
  76. newfile = fopen(name1, "w+");
  77. fill(file);
  78. puts("content");
  79. show(file);
  80. task(file, newfile);
  81. puts("new file");
  82. show(newfile);
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement