my very cool new program has a mind boggling probem!!!

This is a discussion on my very cool new program has a mind boggling probem!!! within the C++ Programming forums, part of the General Programming Boards category; In my crappy HTML editor (i emphasize crappy) every time it asks for you to imput a paragraph of information, ...

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    my very cool new program has a mind boggling probem!!!

    In my crappy HTML editor (i emphasize crappy) every time it asks for you to imput a paragraph of information, it just skips it (ie.the program outputs "input paragraph...yadayadaya...but just skips it and goes onto the next thing. Here is my code:
    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    void getFormat();
    void menu();
    void getPara();
    
    int main()
    {
    	remove("HTML Page.html");
    	
    	cout << "        ***********************************************\n";
    	cout << "              Welcome to ChrisHTML version 0.75\n";
    	cout << "        ***********************************************\n";
    	cout << "This version of ChrisHTML now includes the capability to add paragraphs of text\n";
    	cout << "and you may at tags to your text.\n";
    	cout << "Before you can do anything, you must set the text colour\nand the background colour...\n";
    	system("pause");
    	getFormat();
    	menu();
    	
    	ofstream end("HTML Page.html", ios::ate);
    
    	end << "</BODY>\n</HTML>";
    
    	cout << ".:HTML page and source code created:.\n\n";
        
    return 0;
    }
    
    
    void getFormat()
    {
    	char title[50];
    	cout << "\nEnter the title for you page: ";
    	cin.getline(title, 50);
    	cout << "\n";
    
    	int bgcolor;
    	cout << "Enter what colour-code for your background (six digits): ";
    	cin >> bgcolor;
    	cout << "\n";
    
    	int textcolor;
        cout << "Enter the colour for the text (six digits): ";
    	cin >> textcolor;
    	
        ofstream html("HTML Page.html", ios::ate);
    
    	html << "<!--Generated by ChrisHTML 0.7-->\n";
    	html << "<HTML>\n";
    	html << "<HEAD>\n";
    	html << "<TITLE>";
    	html << title;
    	html << "</TITLE>\n";
        html << "<meta name=\"GENERATOR\" content=\"ChrisHTML 0.5\">";
        html << "</HEAD>";
    	html << "<BODY ";
    	html << "bgcolor=";
        html << bgcolor;
    	html << " text=";
    	html << textcolor;
    	html << " >\n";
    }
    
    void menu()
    {
    	int option;
    	cout << "\nHere are you current options:\n";
    	cout << "[1]Add a new paragraph\n[2]Create HTML\n";
    	cout << "(more options in next version)\n";
    	cin >> option;
        
    	switch(option)
    	{
    	case 1:
    		getPara();
    		break;
    
    	case 2:
    		break;
    	
    	default:
    		cout << "\nYou must enter a valid integer\n";
            menu();
        }
    }
    
    void getPara()
    {
    	char para[150];
    	cout << "Enter the text for your new paragrah -  use the <br> tag for a new line,\n";
    	cout << "press enter to stop editing this particular paragragh and go back to the menu:\n";
        cin.getline(para, 150);
    
        ofstream parag("HTML Page.html", ios::ate);
    
    	parag << "\n";
    	parag << "<p>";
    	parag << para;
    	parag << "<p>";
    	parag << "\n";
    
    	cout << "\n";
    
    	menu();
    }
    The area of the code where there is a problem, is here:
    Code:
    cout << "Enter the text for your new paragrah -  use the <br> tag for a new line,\n";
    	cout << "press enter to stop editing this particular paragragh and go back to the menu:\n";
        cin.getline(para, 150);
    Thanks
    -Chris
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  2. #2
    Unregistered
    Guest
    I could be wrong but it looks like you have a recursive function in void menu(). You call menu inside of menu without base case to tell the program to exit.

  3. #3
    Unregistered
    Guest
    Or it may be recursive inside of getpar()

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    oh crap, didn't see that. But would this be causing my problem?
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    32

    Hmm, somthing here maybe!!

    In your main() function you have a line that starts with 'end' that should be endl, and in your switch, you havent got a break; after default: I dont know if it have to be that but I know that you should have one there anyway(the code looks nicer)...

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    I tried putting a break after default: but it didn't work, and the 'end' is just part of the declaration of the ofstream object which creates the html page and was not meant to be an 'endl;'.

    Anybody else...?
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  7. #7
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    : )

    I'm not exactly sure at all, but most of the time when using cin.getline I used the endline character '\n' as the third argument. I'm not sure if this is what would cause it or not, cause I'm a n00b... = )

  8. #8
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Like this (you may already know this, more than I do, but who knows =P)

    cin.getline(para, 150, '\n');

  9. #9
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    nope, thanks but that didn't have any effect of the prog...

    ANYBODY else...?
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  10. #10
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    Ignore any possible character before using a getline. If you used a cin with the extraction operator at any time before using a cin.getline, then the newline character will still be in the buffer and getline will automatically take that as its only input. So try this:
    Code:
        cin.ignore();
        cin.getline(para, 150);
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  11. #11
    I'm Back
    Join Date
    Dec 2001
    Posts
    556

    try this..

    Put another
    cin.getline(para, 150);
    statement after the 1st one and i think you should get the result you want

    so the code should be like ---

    -----
    -----
    ------
    cout << "Enter the text for your new paragrah - use the <br> tag for a new line,\n";
    cout << "press enter to stop editing this particular paragragh and go back to the menu:\n";

    cin.getline(para, 150);
    cin.getline(para, 150);
    ------
    -----
    -----

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    8
    cin.ignore(); would probably work better

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 09:49 PM
  4. check out this cool program i made
    By Leeman_s in forum C++ Programming
    Replies: 9
    Last Post: 12-19-2002, 09:02 PM
  5. Hey check out my really cool program not
    By funkydude9 in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2002, 01:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21