Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <windows.h>
- #define maxStrLen 1024
- void processing(char*);
- void reading(char*);
- int main(int argc, char **argv)
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int c = 0;
- char filenameInp[maxStrLen] = "";
- if (argc == 1) {
- printf("Введите имя входного бинарного файла:\n");
- gets(filenameInp);
- system("CLS");
- } else if (argc == 2) {
- strcpy(filenameInp, argv[1]);
- } else {
- printf("[!] Программе переданы лишние аргументы\n\nВведите <0>, чтобы завершить выполнение программы.\nВведите любое другое значение, чтобы продолжить выполнение программы.\n");
- fflush(stdin);
- c = getchar();
- if (c == '0')
- return 1;
- system("CLS");
- strcpy(filenameInp, argv[1]);
- }
- reading(filenameInp);
- processing(filenameInp);
- reading(filenameInp);
- return 0;
- }
- void processing(char *filenameInp) {
- double t = 0;
- double countDelete = 0;
- FILE * fInp = NULL;
- FILE * fTmp = NULL;
- if ((fInp = fopen(filenameInp, "rb")) == NULL) {
- perror("[!] Ошибка открытия входного бинарного файла");
- getchar();
- return;
- }
- if ((fTmp = fopen("temp.bin", "wb")) == NULL) {
- perror("[!] Ошибка создания временного бинарного файла");
- getchar();
- return;
- }
- while (fread(&t, sizeof(double), 1, fInp)) {
- if (t >= 0)
- fwrite(&t, sizeof(double), 1, fTmp);
- else
- countDelete++;
- }
- fwrite(&countDelete, sizeof(double), 1, fTmp);
- fclose(fInp);
- fclose(fTmp);
- remove(filenameInp);
- rename("temp.bin", filenameInp);
- printf("\nФайл обработан!\n\n");
- }
- void reading(char *filenameInp) {
- FILE * fInp = NULL;
- double t = 0;
- if ((fInp = fopen(filenameInp, "rb")) == NULL) {
- perror("[!] Ошибка открытия входного бинарного файла");
- getchar();
- return;
- }
- printf("Содержимое файла %s: ", filenameInp);
- while (fread(&t, sizeof(double), 1, fInp)) {
- printf("%lf ", t);
- }
- printf("\n");
- fclose(fInp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement