| | |
Question about a loop freezing, or stopping
Thread Solved
![]() |
•
•
Join Date: Dec 2008
Posts: 6
Reputation:
Solved Threads: 0
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:
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:
c++ Syntax (Toggle Plain Text)
//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; } }
Last edited by ohlaph; Dec 12th, 2008 at 4:13 am.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Can't find the solution and looking for help
- Next Thread: Device Manager Window
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets





