Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C file reading stuff

  • 14-03-2007 02: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,652 ✭✭✭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,289 ✭✭✭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