将 mp3 文件的数据复制到另一个文件。 C

Copy data of mp3 file to another file. C

我尝试将数据从 mp3 文件复制到另一个文件。

但是我从文件中得到的所有章程都是“-1”ASCCI。

我用"rb"模式打开scannedFile。

这是代码:

// scannedFile = music.mp3, lastByte = 1000, firstByte = 3
char* data = calloc(lastByte - firstByte + 2, sizeof(char));
for (i = 0; i <= lastByte - firstByte; i++)
{
    c = fgetc(scannedFile);
    if (c == 0) // if the char is 0 ( END OF STRING ) change it for another charter.
        c = 1;
    data[i] = c;
}

看这里:fgetc

它说 return 可以是当前字符或 EOF 字面意思是 -1:

On success, the character read is returned (promoted to an int value). The return type is int to accommodate for the special value EOF, which indicates failure: If the position indicator was at the end-of-file, the function returns EOF and sets the eof indicator (feof) of stream. If some other reading error happens, the function also returns EOF, but sets its error indicator (ferror) instead.

因此您应该查看流的 EOF 指示器以及错误指示器 (ferror) 以获得答案。

好的,我解决了我的问题,我在 fseek 中遇到了问题。 感谢大家的帮助:)