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

C file reading stuff

Options
  • 14-03-2007 2:56pm
    #1
    Registered Users 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 Posts: 6,509 ✭✭✭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 Posts: 7,276 ✭✭✭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 Posts: 3,945 ✭✭✭Anima


    Cheers lads.


Advertisement