I try to copy data from mp3 file to another file.
But all the charter that I get from the file is '-1' ASCCI.
I open scannedFile by "rb" mode.
This is the code:
// 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;
}
Have a look here: fgetc
It says that the return can be either the current char or EOF which is literally -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.
So you should look into the EOF indicator of the stream as well as the error indicator (ferror) for the answer.