Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with opening a file and printer the last 128 bytes of it

vovfiskvovfisk Member Posts: 4
I been trying to write a program that open the file C:mp3.mp3 and prints the last 128 bytes of the file which would be the id3 tag v1. So far it's been an epic fail =(

Comments

  • XLoomXLoom Member Posts: 129
    : I been trying to write a program that open the file C:mp3.mp3 and
    : prints the last 128 bytes of the file which would be the id3 tag v1.
    : So far it's been an epic fail =(
    :

    Would something like this do the trick? (NB! I didn't write any error checking, do it yourself)
    [code]
    #include
    #include

    int main() {
    int bufLength=129;
    FILE* f=fopen("C:\mp3.mp3", "rb");
    fseek(f, 0, SEEK_END);
    long fileLength=ftell(f);
    fseek(f, fileLength-bufLength+1, SEEK_SET);

    char buffer[bufLength];
    memset(buffer, 0, bufLength);
    fread(buffer, 1, bufLength-1, f);
    for(int i=0; i<bufLength; i++) {
    printf("%c", buffer[i]);
    }
    printf("
    ");
    fclose(f);
    return 0;
    }
    [/code]
  • vovfiskvovfisk Member Posts: 4
    : : I been trying to write a program that open the file C:mp3.mp3 and
    : : prints the last 128 bytes of the file which would be the id3 tag v1.
    : : So far it's been an epic fail =(
    : :
    :
    : Would something like this do the trick? (NB! I didn't write any
    : error checking, do it yourself)
    : [code]:
    : #include
    : #include
    :
    : int main() {
    : int bufLength=129;
    : FILE* f=fopen("C:\mp3.mp3", "rb");
    : fseek(f, 0, SEEK_END);
    : long fileLength=ftell(f);
    : fseek(f, fileLength-bufLength+1, SEEK_SET);
    :
    : char buffer[bufLength];
    : memset(buffer, 0, bufLength);
    : fread(buffer, 1, bufLength-1, f);
    : for(int i=0; i<bufLength; i++) {
    : printf("%c", buffer[i]);
    : }
    : printf("
    ");
    : fclose(f);
    : return 0;
    : }
    : [/code]:
    :
    thank you, appreciate the help
Sign In or Register to comment.