Thread: 'Bus Error' using fread

  1. #1
    Registered User no0b's Avatar
    Join Date
    Jan 2009

    'Bus Error' using fread


    I have been struggling with this one for many hours now. Code compiles fine but when I run it I get a 'bus error'. No more details are given by the program. I have narrowed it down to when I call fread.
    #include <math.h>
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <vector>
    using namespace std;
    char *wave;
    char *data;
    char *riff;
    unsigned long int length;
    unsigned int fs, numchannel, bytes, byterate, chunksize, vectsize;
    short nframes, fstart, fend, comp, bits;
    int toggle = 0;
    int *l, *r;
    int main(){
    //open .wav file and verify header works fine problem occurs below
            int *r;
            int *l;
    	int left;
    	int right;
    	for(int i = 0; i <=50; i++){
    		if(toggle%2 == 0){
    			fread(l, 4, 1, audio);
    			left = *l;
    			cout <<<<endl;
    		if (toggle%2 == 1){
    			fread(r, bytes, 1, audio);
    			right = *r;
    			cout <<<<endl;
    		toggle = toggle++;
    It works fine if I just replace left and right with k and j and increment the counters. The problem is when I call fread. I am sure it is something so obvious.

  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    variable l is not initialized pointer,so it points nowhere. And you still hope to sucessfully write to this unknown location? you extend your luck too greately with this hope.
    To be or not to be == true

  3. #3
    Registered User no0b's Avatar
    Join Date
    Jan 2009
    Thanks. I guess I didn't fully understand how to use pointers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fread problems or memory problems
    By Lechuza in forum C Programming
    Replies: 1
    Last Post: 03-22-2009, 12:45 PM
  2. Another link from Microsoft about bug in fread
    By vart in forum A Brief History of
    Replies: 2
    Last Post: 05-06-2008, 11:56 AM
  3. How to load pixels of BMP into an array
    By brconner in forum Windows Programming
    Replies: 10
    Last Post: 06-02-2007, 04:30 AM
  4. Why is fread sometimes taking so long?
    By manugarciac in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2007, 11:25 PM
  5. fread: Bus error
    By fnoyan in forum Linux Programming
    Replies: 4
    Last Post: 08-20-2004, 10:30 AM
Website Security Test