Thread: Program Needed!!

  1. #1
    Registered User
    Join Date
    May 2002

    Unhappy Program Needed!!


    Pls help me out...My prog crashes when I start reading the text file......It reads the names......but cant go further....
    It was working perfect initially when the gender was kept as string..
    But our teacher wants it to be read as char.....

    Error message is DEBUG error----Abnormal program termination-Press retry to debug the application........


    thanks a lot.

    int adatabase(competitor database[], int &tmprec , int &tempID)
        int i =0;
        string tempString="abs";
         ifstream inputFile("records.txt", ios::in );
        tempID= atoi(readFileLine(inputFile).c_str());
         /*if(inputFile.seekg(0, ios::end))
    	cout<<"file is empty"<<endl;
    	tmprec =0;
            while(!inputFile.eof() && tmprec < DATABASESIZE)
           database[tmprec].competitorName= readFileLine(inputFile);
            database[tmprec].ID = atoi(readFileLine(inputFile).c_str());
           tempString = readFileLine(inputFile);
          char compGend=;//PROBLEM LIES HERE..I     SUPPOSE
            database[tmprec].compGender = compGend;
            database[tmprec] atoi(readFileLine     (inputFile).c_str());
            database[tmprec].birthDate.month = atoi(readFileLine(inputFile).c_str());
           database[tmprec].birthDate.year = atoi(readFileLine(inputFile).c_str());
    tmprec= tmprec++; 
    return tmprec;
    return tempID;
    string readFileLine(ifstream &inputFile)
        char buffer[SIZE];
        inputFile.getline(buffer, SIZE, '\n');
        return buffer;
    SIZE is a global constant : const int SIZE = 81;

  2. #2
    Registered User
    Join Date
    Apr 2002
    You're reading
    tempString = readFileLine(inputFile);
    one char at a time, except...

    ...the at() function requires a loop as though you were reading one char at a time from an array.

    Little complicated.

    You need the length of the string that you're reading first.

    int tempStringLen = tempString.length();
    for (int x = 0; x < tempStringLen; x++)
         char compGend =;
    (I would declare 'compGend' earlier to avoid a possible warning/error.)

    I'm doing a little scrambling here, but it should give you something to work with.
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  3. #3
    Registered User
    Join Date
    May 2002

    Smile thanks

    thanks Skipper , ur a genius....

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    >Press retry to debug the application........

    Silly question maybe, but did you ? The debugger is the most usefull tool for fixing crashes. Learn to use it.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User
    Join Date
    May 2002
    try this:
    ifstream fin("filename.nam");

    for example.
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 12-31-2007, 06:26 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM
  5. Program crashes and I can't figure out why
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-19-2001, 05:33 PM