Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <cstring>
- #include "ctime"
- #include "math.h"
- #include <tchar.h>
- #include <cstring>
- #include "stdlib.h"
- #include <string>
- #include "conio.h"
- #include <fstream>
- using namespace std;
- FILE show(FILE* file)
- {
- rewind(file);
- char* string;
- string = new char[128];
- while (fgets(string, 128, file) > 0)
- puts(string);
- return(*file);
- }
- FILE fill(FILE* file)
- {
- rewind(file);
- char* string;
- string = new char[128];
- while (gets_s(string, 128), strlen(string) != 0)
- {
- fputs(string, file);
- fputs("\n", file);
- }
- return (*file);
- }
- FILE* task(FILE* file, FILE* newfile)
- {
- float sum = 0;
- int count = 0;
- char name[3];
- rewind(file);
- char* string;
- string = new char[128];
- while (fgets(string, 128, file) > 0)
- {
- char* pch = strtok(string, " ");
- fputs(pch, newfile);
- fprintf(newfile, " ");
- pch = strtok(NULL, " ");
- strncpy(name, pch, 1);
- name[1] = '.';
- name[2] = '\0';
- fputs(name, newfile);
- fprintf(newfile, " ");
- pch = strtok(NULL, " ");
- while (pch != NULL)
- {
- sum += atoi(pch);
- count++;
- pch = strtok(NULL, " ");
- }
- sum /= count;
- fprintf(newfile, "%4f\n", sum);
- count = 0;
- sum = 0;
- }
- return newfile;
- }
- int main() {
- srand(time(NULL));
- FILE* file;
- FILE* newfile;
- char name[] = "my.txt";
- char name1[] = "my1.txt";
- file = fopen(name, "w+");
- newfile = fopen(name1, "w+");
- fill(file);
- puts("content");
- show(file);
- task(file, newfile);
- puts("new file");
- show(newfile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement