Yes, here's an example program that does that:

#include <stdio.h>

int main() {
    FILE *input_file = fopen("input.txt", "rb");
    FILE *output_file = fopen("output.txt", "wb");

    // Read first 1024 bytes and invert their order
    unsigned char buffer[1024];
    fread(buffer, 1, 1024, input_file);
    for (int i = 0; i < 512; i++) {
        unsigned char tmp = buffer[i];
        buffer[i] = buffer[1023 - i];
        buffer[1023 - i] = tmp;
    }
    fwrite(buffer, 1, 1024, output_file);

    // Read and write the rest of the file byte by byte
    int c;
    while ((c = fgetc(input_file)) != EOF) {
        fputc(c, output_file);
    }

    fclose(input_file);
    fclose(output_file);
    return 0;
}

Assuming the input file is named "input.txt" and the output file is named "output.txt", this program will read the first 1024 bytes from the input file, invert their order, and write them to the output file. Then it will read the rest of the input file byte by byte and write each byte to the output file.

Note that this program assumes that the input file is at least 1024 bytes long. If the input file is shorter than that, the program will still try to read 1024 bytes and may read garbage data or crash. To handle this case correctly, you would need to check the return value of fread() to see how many bytes were actually read

Can you write a C program that reads 1024 bytes from a first file inverts their order write them to a second file afterwards read the rest of the file byte to byte an write them to the secon

原文地址: https://www.cveoy.top/t/topic/dflS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录