CS50反向:错误:ENOSPC:设备上没有剩余空间,写入)

问题描述 投票:0回答:0

所以,在我编译并运行反向问题 (PS4) 之后,我的代码空间崩溃了,我无法用它做任何事情,因为它吐出这个:错误:ENOSPC:设备上没有剩余空间,写)

我试过清空临时文件夹,没有用。我看了看

df -i
,它说我有足够的可用空间。所以现在我不知道该怎么办。也许我的程序代码会有所帮助

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include "wav.h"

bool check_format(WAVHEADER header);
int get_block_size(WAVHEADER header);

int main(int argc, char *argv[])
{
    // Ensure proper usage
    if(argc != 3)
    {
        printf("Usage: ./reverse input.wav output.wav\n");
        return 1;
    }

    // Open input file for reading
    FILE *input = fopen(argv[1], "r");
    if(input == NULL)
    {
        printf("Can't open the file\n");
        return 2;
    }

    // Read header
    WAVHEADER header;
    fread(&header, sizeof(WAVHEADER), 1, input);

    // Use check_format to ensure WAV format
    if (!check_format(header))
    {
        printf("Unsupported file format\n");
        fclose(input);
        return 3;
    }


    // Open output file for writing
    FILE *output = fopen(argv[2], "w");
    if(output == NULL)
    {
        fclose(input);
        return 4;
    }

    // Write header to file
    fwrite(&header, sizeof(WAVHEADER), 1, output);

    // Use get_block_size to calculate size of block
    int block_size = get_block_size(header);
    long int header_position = ftell(input);

    // Write reversed audio to file
    int block_array[block_size];
    fseek(input, 0, SEEK_END);

    while(fread(&block_array, sizeof(int), block_size, input) >= 0)
    {

        fwrite(&block_array, sizeof(int), block_size, output);
        fseek(input, -(2 * block_size), ftell(input));

        if(ftell(input) <= header_position)
        {
            fclose(output);
            break;
        }
    }

    fclose(input);
}
c out-of-memory github-codespaces
© www.soinside.com 2019 - 2024. All rights reserved.