Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C file reading stuff

  • 14-03-2007 1:56pm
    #1
    Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭


    Hey,

    I'm trying to read info from a wav header. I have to extract the sampling frequency and a few other details. I can do this with a pretty easy method but I'm trying to do it another way.
    FILE *p;
    	int buffer[6]={0},x;
    
    	//open the file
    	p=fopen("sine.wav","rb");
    		
    	//read the file
    	fread(buffer,sizeof(char),4,p);	//read sampling rate
    

    Instead of just reading each piece of data bit by bit, I want to just select which data I want. My lecturer said I could increment the pointer "p" to create a kind of offset and just read which part I want. I can't seem to get it right though. Is it possible to do it this way?


Comments

  • Registered Users, Registered Users 2 Posts: 6,570 ✭✭✭daymobrew


    Look at fseek.
    /* nError will be 0 on success, -1 otherwise. */
    nError = fseek( p, nOffsetFromStart, SEEK_SET );
    
    Changing 'p' directly is not right. Either the lecturer is wrong or maybe you misheard/misinterpreted the info.


  • Registered Users, Registered Users 2 Posts: 7,278 ✭✭✭kenmc


    Yeah as Damo says don't change 'p' - it is the handle to your file - if you try to close the file handle and it has been moved who knows what the hell will happen!?

    So If I fully understand your question:
    Rather than read in the first 4 bytes to only use the 4th one, you want to just read in the 4th one alone?
    So yeah - the sequence would be something like
    fopen()
    fseek(offset=4)
    fread(1 byte)
    whatever else
    fclose


  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    Cheers lads.


Advertisement