Question about a loop freezing, or stopping

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 6
Reputation: ohlaph is an unknown quantity at this point 
Solved Threads: 0
ohlaph ohlaph is offline Offline
Newbie Poster

Question about a loop freezing, or stopping

 
0
  #1
Dec 12th, 2008
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:

  1. //Step 1: Setup and Define the variables
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cstring>
  5. #include <cctype>
  6. using namespace std;
  7.  
  8. void checkstuff( char course[], char desc[], char due[], char request[]);
  9. int main() {
  10. //Local variables
  11. char course[70];
  12. char due[70];
  13. char desc[70];
  14. char fname[70];
  15. char request[25];
  16.  
  17. strcpy(request, "cs161");
  18. /* To be un commented when rest of program is working okay
  19.  
  20. //Step 2: Welcome the user and get the file name and class request
  21. //Welcome message and file request
  22. 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;
  23. cin.get(fname, 70, '\n');
  24. cin.ignore();
  25.  
  26. //Prompt for the class they are looking for and store it in request
  27. cout << "What class are you looking for?" << endl;
  28. cin >> request;
  29. cin.ignore();
  30. cout << endl;
  31. */
  32. //Step 4: open file and check to see if it's open
  33. ifstream filein;
  34. filein.open ("crazy.txt");
  35.  
  36. if (filein) {
  37.  
  38. //Step 5: Read in first line and check for end of file
  39. filein.get(course, 70, '\n');
  40. filein.get();
  41.  
  42. while (!filein.eof()) {
  43.  
  44. //Step 6: Read in second and third lines and check it to see if it matches the class request
  45. filein.get(due, 70, '\n');
  46. filein.get();
  47. filein.get(desc, 70, '\n');
  48. filein.get();
  49.  
  50. //Send it to the function
  51. checkstuff(course, due, desc, request);
  52.  
  53. //Step 7: Continue checking file
  54. filein.get(course, 70, '\n');
  55. filein.get();
  56. }
  57. }
  58. filein.close();
  59.  
  60. //Step 8: End of file has been reached, say good-bye
  61. cout << "The end of the file has been reached, thanks for using this program and good-bye!" << endl;
  62.  
  63. return (0);
  64. }
  65.  
  66. //This function checks the class request and echo's if it matches
  67. void checkstuff( char course[], char due[], char desc[], char request[]) {
  68.  
  69. //Step 1-function: check the request for a match
  70. if (strcmp(course, request) == 0) {
  71.  
  72. //Step 2-function: echo the result
  73. cout << course <<endl;
  74. cout << due << endl;
  75. cout << desc << endl;
  76. cout << endl;
  77. }
  78. }
Last edited by ohlaph; Dec 12th, 2008 at 4:13 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC