I'm sorry I keep having these strange problems but there's little I can do about them, they are unpredictable.

I managed to fix the last one and I've been able to compile and run my programs.

Now however I've run in to the *strangest *of problems, the one described in the title.

I've set breakpoints in the constructor call and the header I created; and the program just skips past everything and straight to return. I have a picture: ProgramSkip.GIF

My code does some cout statements in the header (for debugging) so there should be something in the command line window! Yet there isn't and none of the breakpoints I set in the header or the source file were hit! I have a feeling this has to do with the codeblocks IDE.

For the record it does the same thing with the release target!

Does anyone know why this might be? Maybe someone with experience with codeblocks?

Edited 1 Year Ago by Curious Gorge

Ok here we are:

File.h:

#ifndef FILEREADER_H_INCLUDED
#define FILEREADER_H_INCLUDED

#endif // FILEREADER_H_INCLUDED

#ifndef STRING_INCLUDED
#define STRING_INCLUDED
#include <string.h>

#endif // STRING_INCLUDED
#ifndef FSTREAM_INCLUDED
#define FSTREAM_INCLUDED
#include <fstream>
#endif // FSTREAM_INCLUDED

#ifndef SSTREAM_INCLUDED
#define SSTREAM_INCLUDED
#include <sstream>
#endif // SSSTREAM_INCLUDED

#ifndef IOSTREAM_INCLUDED
#define IOSTREAM_INCLUDED
#include <iostream>
#endif // IOSTREAM_INCLUDED

#include <cstdlib>

#define fileName "ScheduleDataBIN.txt\0"


*/class ScheduleFile
{
private:
    int LINELEN;
    int numOfRecords;
    bool is_open_flag;
    int *dataPtr; //To point to the file data;

      int *yrPtr;
    int *monthPtr;
    int *dayPtr;
    int *hourPtr;
    int *minutePtr;
    char *am_pmPtr; //Maximum of 8 records by four chars (two for AM/PM and + 1 for null byte) long.
    char *namePtr; //Name can only be 160 chars long including null termination byte.
    std::fstream file; //Private class member file is to be accessed by member foo's to get the file.


    int recordNum; //Index of which record to access.
    void getData (); //Gets the data out of the file and puts it in to the corresponding fields.
    void writeData(); //Writes the [new] fields to the file.
    void sortData ();
public:

    ScheduleFile()
    {
        LINELEN = 180;
        file.open(fileName, std::fstream::in | std::fstream::out | std::fstream::binary); //Open file using null terminated c string in binary mode.
        if(file.is_open() )
        {
            is_open_flag = true; //To let the programmer know when the file is open.

            recordNum = 0;
            numOfRecords = 1;
            getData(); //Put the data in to the fields.
        }
        else
        {
            is_open_flag = false;
        }


    }


    void seekNextRecord ();
    int getYr(int recIndex);
    int getMnth(int recIndex);
    int getDay(int recIndex);
    int getHour(int recIndex);
    int getMinute(int recIndex);
    void getAM_PM(int recIndex, char *arrayptr);
    void getName(int recIndex, char *arrayPtr);
    std::string getEventName();


};

void ScheduleFile::getData() { //Unfinished.
    int size;

     file.seekg(0, std::fstream::end); //Find the end of the file.
     size = file.tellg(); //Put how long the file is in to size.
     dataPtr = (int*)malloc(size * sizeof(char)); //Allocate enough memory to hold the entire file.
     if(dataPtr == NULL) {
        std::cout << "ERROR. Unable to allocate memory!";
        exit(-1);

     }
     file >> *dataPtr;
     std::cout << "Data in dataPtr is: " << *dataPtr << " File is: " <<  size << "Bytes long.";

return;
}

and TestWithScheduleFile.cpp:

#include "File.h"

#include <iostream>

int main () {

ScheduleFile mySchedule();

return 0;
}

The creation of the ScheduleFile object calls its constructor, which opens the file using the #define in "File.h" , which then calls "getData()" which is at this point unfinished.

Oh! That makes more sense! I thought just adding parantheses when creating an object called the objects constructor! XD Sorry I'm having trouble thinking clearly today lack of sleep does that!

This article has been dead for over six months. Start a new discussion instead.