Thread: Segmentation Fault :(

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    109

    Segmentation Fault :(

    Hey I have a segmentation fault and can't locate it,maybe one of you can.
    Main:
    Code:
    #include <queue>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include "rider.h"
    
    using namespace std;
    
    int main()
    {
        //variable used to count the ticket
        int tickets;
    
        //variable used to keep time
        int clock;
    
        //tmp variable used in loops as counter
        int i;
    
        //queue that the information from the infile gets stored into 
        queue<rider> arrivals;
    
        //queue that the riders with the correct clock time get put into
        queue<rider> line;
    
        //queue that the rider that needs to be put back in line gets held
        queue<rider> backIn;
    
        //string that makes it easier to remember the name of the file to open
        //to read from
        string  inFileName = "riders.dat";
    
        //string that makes it easier to remember the name of the file to open
        //to write to
        string  outFileName = "riders.out";
       
        //file read from
        ifstream inFile;
    
        //file write to
        ofstream outFile;
        
        //opens the file to read from
        inFile.open(inFileName.c_str());
    
        //opens the file to write to
        outFile.open(outFileName.c_str());
    
        //sets the clock to 0
        clock = 0;
    
        //creates customer of the struct rider;
        rider customer;
    
        //while the infile can be read from
        while(inFile)
        {
    
        //it will loop and read from the inFile data while the customer data
        //is not equal to END 0 0 
        while(!(customer.lastName == "END" && customer.tickets == 0 && customer.time ==0))
        {
            //here the file will place the correct data for each customer into 
            //the correct variables
            inFile >> customer.lastName >> customer.tickets >> customer.time;
    	
            //after the customer in that particular read is done putting it in the
            //correct variables the customer gets pushed ito arrivals queue
            arrivals.push(customer);
        }
    
        //once all the customers are read from the inFile and put into the arrivals
        //queue the program and clock will have to be run where this data will be 
        //processed. For the processing part of the program, it will run while
        //the queues arrivals and line are not empty, therefore they will stop
        //running when they become empty.
        while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
        {
            //makes transfer a variable of type rider equal to the front of the
            //arrivals queue
            rider transfer = arrivals.front();
        
        //this will look to see if the transfer arrival time is equal to 0, if not
        //it will set clock equal to that number then copy all the transfers that
        //have that clock number.
        
            //checks to see if the transfer time is equal to the clock time
            if(!line.empty())
            {
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(transfer);
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
               
                //need to check to see if backIn is empty or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(!backIn.empty())
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn.front());
               
                }     
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //increments clock by 1 unit
                clock++;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //places the customer on the ride's data into the backIn 
                    //queue so they may get placed back in line 
                    backIn.push(onRide);
                }
            }
            //else if the first customers time is not equal to the clock it
            //sets clock equal to that customers time then continues on 
            else
            {
                //sets clock equal to the first customers time
                clock = transfer.time;            
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(arrivals.front());
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
    
                //need to check to see if backIn is empty or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(!backIn.empty())
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn.front());
               
                }  
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //increments clock by 1 unit
                clock++;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //places the customer on the ride's data into the backIn 
                    //variable so they may get placed back in line 
                    backIn.push(onRide);
                }
            }
        }
    }
    
        //closes the infile
        inFile.close();
    
        //closes the outfile          
        outFile.close();
    
        //signals ok to the os
        return 0;
    };
    riders.h:
    Code:
    #include<string>
    
    using namespace std;
    
    //this is a struct named Rider that will be used to store all the data of a
    //rider on the fair ride, this makes it easier so that I can make a queue of
    //type rider instead of multiple queues for each data type of data
    struct rider
    {
        //variable for last name of rider
        string lastName;
    
        //variable for number of tickets the rider has
        int tickets;
    
        //variable for the arrival time of the rider
        int time;
    };

  2. #2
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    You have to initialize customer before using it.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    41
    Don't know if this is it, but you appear to have an infinite loop here:

    Code:
              //sets clock equal to the first customers time
                clock = transfer.time;            
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock) //always true?
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(arrivals.front());
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    One problem is this:

    Code:
    while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
        {
            rider transfer = arrivals.front();
    There is no guarantee that arrivals is not empty at this point, in which case you should not call front() and use the return value.

    I also think that a queue is only required to implement the actual queue.
    As only one person can be riding at a time, you don't need a container for it (but you can, of course). When I tried to write it, I used an empty rider, whose name was "END" for idle rides.
    The list of arrivals should probably be sorted according to time of arrival. This way it is a simple matter of checking the first (or last) item on the list to determine, if they should be added to the queue. (You can't sort a queue container, it is not meant for that.)

    Then you need to think, what exactly happens during each cycle and in which order.

    1) Check for new arrivers, and add them to the queue if any;
    2) Check the current rider, if any, and push back to the queue if tickets left;
    3) If queue is not empty, assign front to rider and pop.
    4) Increment time.

    (There are a bit too many comments. You should be at a level where you don't need to comment each and every line, as they are reducing readability of the code. May-be comment what a block does, or just the general logic before the loop.)
    Last edited by anon; 04-04-2007 at 10:20 AM.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    the infile will always be written in time arrival order, therefore there is no reason to sort before hand.

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    OK, I misunderstood that.

    Well, you should not call front() unless you are sure that it is !empty().

    Code:
    //while (infile) //better replace with
    
    if (!infile)
        return -1;
    Infinite loop, because transfer is not modified. Infinite number of riders pushed onto the queue:
    Code:
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(transfer);
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
    Also, why do you do it only if line is not empty? Or rather, why do you have the same code in both cases?

    Look at the steps I mentioned. At least backIn is not required: there can be only one rider at a time, so there can be only one rider to go back in at a time. You can move it directly from whatever you use it to the back of the line.

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    here is my updated code, i'm still getting a segmentation fault. And i don't think its an infinite loop because what its supposed to do is while people with the time equal to the clock get taken from the arrivals queue and are put into the line queue. Then the rider in the front of the line queue rides the ride , then the ticket is taken from the rider. If the rider has no more tickets it gets written to the outfile and if the rider does have more tickets he gets placed at the end of the line queue are the people who have time equal to the new clock time that was incremented. Then the whole thing is run until the arrivals, line and backIn queue are empty. Any help here would be great fully appreciated as always.
    Code:
    //Filename:main.cpp
    //Author:Brandon Kruter
    //Project: 8
    //CS174
    
    #include <queue>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include "rider.h"
    
    using namespace std;
    
    int main()
    {
        //variable used to count the ticket
        int tickets;
    
        //variable used to keep time
        int clock;
    
        //tmp variable used in loops as counter
        int i;
    
        //queue that the information from the infile gets stored into 
        queue<rider> arrivals;
    
        //queue that the riders with the correct clock time get put into
        queue<rider> line;
    
        //queue that the rider that needs to be put back in line gets held
        queue<rider> backIn;
    
        //string that makes it easier to remember the name of the file to open
        //to read from
        string  inFileName = "riders.dat";
    
        //string that makes it easier to remember the name of the file to open
        //to write to
        string  outFileName = "riders.out";
       
        //file read from
        ifstream inFile;
    
        //file write to
        ofstream outFile;
        
        //opens the file to read from
        inFile.open(inFileName.c_str());
    
        //opens the file to write to
        outFile.open(outFileName.c_str());
    
        //creates customer of the struct rider;
        rider customer;
    
        //while the infile can be read from
        while(inFile)
        {
    
        //it will loop and read from the inFile data while the customer data
        //is not equal to END 0 0 
        while(!(customer.lastName == "END" && customer.tickets == 0 && customer.time ==0))
        {
            //here the file will place the correct data for each customer into 
            //the correct variables
            inFile >> customer.lastName >> customer.tickets >> customer.time;
    	
            //after the customer in that particular read is done putting it in the
            //correct variables the customer gets pushed ito arrivals queue
            arrivals.push(customer);
        }
    
        //once all the customers are read from the inFile and put into the arrivals
        //queue the program and clock will have to be run where this data will be 
        //processed. For the processing part of the program, it will run while
        //the queues arrivals and line are not empty, therefore they will stop
        //running when they become empty.
        while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
        {
            //makes transfer a variable of type rider equal to the front of the
            //arrivals queue
            rider transfer = arrivals.front();
        
        //this will look to see if the transfer arrival time is equal to 0, if not
        //it will set clock equal to that number then copy all the transfers that
        //have that clock number.
        
            //checks to see if the transfer time is equal to the clock time
            if(!line.empty())
            {
    
                //sets clock equal to -1 so that when it first increments
                //it wil be equal to 0
                clock = -1;
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(transfer);
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
               
                //need to check to see if backIn is empty or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(!backIn.empty())
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn.front());
               
                }     
              
                //remove the rider in backIn
                backIn.pop();
     
                //increment clock
                clock++;
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //places the customer on the ride's data into the backIn 
                    //queue so they may get placed back in line 
                    backIn.push(onRide);
                }
            }
            //else if the first customers time is not equal to the clock it
            //sets clock equal to that customers time then continues on 
            else
            {
                //sets clock equal to the first customers time
                clock = transfer.time;            
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(arrivals.front());
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
    
                //need to check to see if backIn is empty or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(!backIn.empty())
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn.front());
               
                }  
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //increments clock 
                clock++;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //places the customer on the ride's data into the backIn 
                    //variable so they may get placed back in line 
                    backIn.push(onRide);
                }
            }
        }
    }
    
        //closes the infile
        inFile.close();
    
        //closes the outfile          
        outFile.close();
    
        //signals ok to the os
        return 0;
    };

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I'm fairly sure that your rider struct needs to implement at the very least the copy constructor for when you're pushing things into STL containers.

    Without such a function, you just get shallow bit-wise copies, which inevitably means you'll end up with multiple pointers to the same memory for those strings you have inside the struct.

    char lastName[50];
    say, would not have this problem, and might prove the point.

    Code:
    }
    
        //closes the infile
        inFile.close();
    
        //closes the outfile          
        outFile.close();
    
        //signals ok to the os
        return 0;
    };
    Indent your code properly, two closing braces in column 1 just looks weird.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    I changed the while(transfer.time == clock) to if(transfer.time == clock) now it just hangs then i get the message Killed after. Any idea?

  10. #10
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    if someone could tell me whats wrong please help me

  11. #11
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    i havent been following this thread, but if you post an update of your current code, the error, and the condition (if you know) where this error occurs ill gladly take a look.

  12. #12
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    Here is the updated code
    Code:
    #include <queue>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include "rider.h"
    
    using namespace std;
    
    int main()
    {
        //variable used to keep time
        int clock;
    
        //queue that the information from the infile gets stored into 
        queue<rider> arrivals;
    
        //queue that the riders with the correct clock time get put into
        queue<rider> line;
    
        //queue that the rider that needs to be put back in line gets held
        queue<rider> backIn;
    
        //string that makes it easier to remember the name of the file to open
        //to read from
        string  inFileName = "riders.dat";
    
        //string that makes it easier to remember the name of the file to open
        //to write to
        string  outFileName = "riders.out";
       
        //file read from
        ifstream inFile;
    
        //file write to
        ofstream outFile;
        
        //opens the file to read from
        inFile.open(inFileName.c_str());
    
        //opens the file to write to
        outFile.open(outFileName.c_str());
    
        //creates customer of the struct rider;
        rider customer;
    
        //while the infile can be read from
        while(inFile)
        {
    
        //it will loop and read from the inFile data while the customer data
        //is not equal to END 0 0 
        while(!(customer.lastName == "END" && customer.tickets == 0 && customer.time ==0))
        {
            //here the file will place the correct data for each customer into 
            //the correct variables
            inFile >> customer.lastName >> customer.tickets >> customer.time;
    	
            //after the customer in that particular read is done putting it in the
            //correct variables the customer gets pushed ito arrivals queue
            arrivals.push(customer);
        }
    
        //once all the customers are read from the inFile and put into the arrivals
        //queue the program and clock will have to be run where this data will be 
        //processed. For the processing part of the program, it will run while
        //the queues arrivals and line are not empty, therefore they will stop
        //running when they become empty.
        while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
        {
            //makes transfer a variable of type rider equal to the front of the
            //arrivals queue
            rider transfer = arrivals.front();
        
        //this will look to see if the transfer arrival time is equal to 0, if not
        //it will set clock equal to that number then copy all the transfers that
        //have that clock number.
        
            //checks to see if the transfer time is equal to the clock time
            if(!line.empty())
            {
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                if(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(transfer);
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
               
                //need to check to see if backIn is empty or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(!backIn.empty())
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn.front());
                    
                //remove the rider in backIn
                backIn.pop();
    	
                } 
    
                //increment clock
                clock++;
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //places the customer on the ride's data into the backIn 
                    //queue so they may get placed back in line 
                    backIn.push(onRide);
                }
            }
            //else if the first customers time is not equal to the clock it
            //sets clock equal to that customers time then continues on 
            else
            {
                //sets clock equal to the first customers time
                clock = transfer.time;            
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                if(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(arrivals.front());
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
    
                //need to check to see if backIn is empty or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(!backIn.empty())
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn.front());
               
                //get ride of the rider in the backIn queue
                backIn.pop();
                }  
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //increments clock 
                clock++;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //places the customer on the ride's data into the backIn 
                    //variable so they may get placed back in line 
                    backIn.push(onRide);
                }
            }
        }
    }
    
        //closes the infile
        inFile.close();
    
        //closes the outfile          
        outFile.close();
    
        //signals ok to the os
        return 0;
    };
    i have no idea where the problem could be. When i run it it just hangs and freezes eventually. There is no compile error, it compiles but then running it presents the above problem.

  13. #13
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    did riders.h change or is it same as in your first post?

    edit: can you also supply some tester code that i can run.. it would be very difficult to solve a problem that i dont know what it is, where it is, or when it occurs.
    Last edited by nadroj; 04-05-2007 at 10:58 PM.

  14. #14
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    riders.h didn't change and same code is as follows in a riders.dat file that the program writes to the outfile riders.out
    Code:
    Hopper 2 1 Torvalds 3 10 Jobs 8 4 Gates 100 100 END 0 0

  15. #15
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318

    Cool Here's a tip...

    Don't use so many freaking comments...

    You have grosely over-commented, which is as bad as under-commenting.
    First remove the pointless comments for things that are bloomin obvious, like:

    file read from
    file write to
    creates customer of the struct rider
    increment clock
    closes the infile

    That might make it easier to see the problem!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 03:36 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM