DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Question about a loop freezing, or stopping (http://www.daniweb.com/forums/thread161896.html)

ohlaph Dec 12th, 2008 4:09 am
Question about a loop freezing, or stopping
 
I'm working on this project due by 4AM and my loop keeps stopping after following part of a loop. I've checked the code several times, but it just freezes inside the checkstuff function. Can someone tell me how I can break from that fucntion or loop and continue looping through a text file please?

The loop that calls the function is the loop I want to get back into after the function is called and executed, any suggestions?

Here is the code:

//Step 1: Setup and Define the variables
#include <iostream>
#include <fstream>
#include <cstring>
#include <cctype>
using namespace std;
 
 void checkstuff( char course[], char desc[], char due[], char request[]);
int main() {
        //Local variables
        char course[70];
        char due[70];
        char desc[70];
        char fname[70];
        char request[25];

        strcpy(request, "cs161");
        /* To be un commented when rest of program is working okay
       
        //Step 2: Welcome the user and get the file name and class request
        //Welcome message and file request
        cout << "Welcome to the program, this program will read assignments from a file for you based on what class you're looking for.  But first, what file would you like to look in?" << endl;
        cin.get(fname, 70, '\n');
        cin.ignore();
       
        //Prompt for the class they are looking for and store it in request
        cout << "What class are you looking for?" << endl;
        cin >> request;
        cin.ignore();
        cout << endl;
*/
        //Step 4: open file and check to see if it's open
        ifstream filein;
        filein.open ("crazy.txt");

        if (filein) {
       
                //Step 5: Read in first line and check for end of file
                filein.get(course, 70, '\n');
                filein.get();

                while (!filein.eof()) {
                       
                        //Step 6: Read in second and third lines and check it to see if it matches the class request
                        filein.get(due, 70, '\n');
                        filein.get();
                        filein.get(desc, 70, '\n');
                        filein.get();
                       
                        //Send it to the function
                        checkstuff(course, due, desc, request);
                       
                        //Step 7: Continue checking file
                        filein.get(course, 70, '\n');
                        filein.get();
                }
        }
        filein.close();
       
        //Step 8: End of file has been reached, say good-bye
        cout << "The end of the file has been reached, thanks for using this program and good-bye!" << endl;
       
        return (0);
}

//This function checks the class request and echo's if it matches
 void checkstuff( char course[], char due[], char desc[], char request[]) {
 
        //Step 1-function: check the request for a match
        if (strcmp(course, request) == 0) {
       
                //Step 2-function: echo the result
                cout << course <<endl;
                cout << due << endl;
                cout << desc << endl;
                cout << endl;
        }
 }


All times are GMT -4. The time now is 5:25 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC