unwanted blankness

This is a discussion on unwanted blankness within the C++ Programming forums, part of the General Programming Boards category; Ok cross everything out, I got it to check the error, it checks it, if its <=1 or >3 then ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    unwanted blankness

    Ok cross everything out, I got it to check the error, it checks it, if its <=1 or >3 then it goes back to wanting to know what the string is but if it is a correct answer it just goes to a blank line
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        int X;
        X=1;
        while(X=1)
        {
            char option[3];
            cout<<"Are you going to want to loop?\nYes or No: ";
            cin>>option;
            if(sizeof(option)<=1)
            {
                cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)";
                cin.get();
            }
            if(sizeof(option)>3)
            {
                cout<<"This isn't the time for buffer overflows yet";
                cin.get();
            }
            else
            {
                if(strcmp(option,"Yes")==0||strcmp(option,"yes")==0)
                {
                    char buffer[10];
                    cin>>buffer;
                    cout<<buffer;
                    cin.ignore();
                    cin.get();
                }
                if(strcmp(option,"No")==0||strcmp(option,"no")==0)
                {
                    char buffer[10];
                    cin>>buffer;
                    cout<<buffer;
                    cin.ignore();
                    cin.get();
                    X=0;
                }
            }
        }
        cin.get();
        return 0;
    }
    Last edited by bikr692002; 02-28-2006 at 02:03 PM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >            if(strcmp(option,"Yes")==0||strcmp(option,"yes")==0)
    >            {
    >                char buffer[10];
    >                cin>>buffer;
    cin >> buffer;
    Can you rephrase your question? cin stands for console input. So this line waits for the user to enter something.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Yeah just saw that :-P, Thanks, stupid mistake ^.^

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Ok but now for every error, its saying same size as yes, but not yes.... instead of me entering KK and it saying same size as no, but not no
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        int X;
        X=1;
        while(X=1)
        {
            char option[3];
            cout<<"Are you going to want to loop?\nYes or No: ";
            cin>>option;
            if(sizeof(option)<2)
            {
                cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)";
            }
            if(sizeof(option)>3)
            {
                cout<<"This isn't the time for buffer overflows yet";
            }
            if(sizeof(option)==3&&!(strcmp(option,"yes")==0||strcmp(option,"Yes")==0))
            {
                cout<<"Tisk tisk, you tried to fool me by entering something the same size as yes, but not yes.\n";
            }
            if(sizeof(option)==2&&!(strcmp(option,"No")==0||strcmp(option,"no")==0))
            {
                cout<<"Tisk tisk, you tried to fool me by entering something the same size as no, but not no.\n";
            }    
            else
            {
                if(strcmp(option,"Yes")==0||strcmp(option,"yes")==0)
                {
                    char buffer[10];
                    cout<<"Ok, now try to overflow me\n";
                    cin>>buffer;
                    cout<<buffer;
                    cin.ignore();
                    cin.get();
                }
                if(strcmp(option,"No")==0||strcmp(option,"no")==0)
                {
                    char buffer[10];
                    cout<<"Ok, now try to overflow me\n";
                    cin>>buffer;
                    cout<<buffer;
                    cin.ignore();
                    cin.get();
                    X=0;
                }
            }       
        }
        return 0;
    }
    and if i type no it says the yes error but brings me to the overflow point
    eDIT: Ahhh, should change to two first ||'s to &&'s
    Brb
    Last edited by bikr692002; 02-28-2006 at 02:28 PM.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > while(X=1)
    Remember = is assignment, and == is equality:
    Code:
        while(X==1)
    > char option[3];
    Remember this can only hold two characters plus the string terminator. So if you want it to hold "yes", it needs to have 4 elements:
    Code:
            char option[4];
    > if(sizeof(option)<2)
    Instead of sizeof, use strlen() to find a char array's length:
    Code:
            if(strlen(option)<2)
    To use strlen(), include <cstring>.

    Why not use the string class instead. Then you can do stuff like:
    Code:
       string option;
    .
    .
       if (option.length() < 2)
       {
    .
    .
       else
       {
          if (option == "Yes" || option == "yes")
          {

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    How do we use the string class?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Try the tutorials.

    Use = for assignment and + for concatention.
    Code:
    string firstname = "joe";
    string lastname = "smith";
    string fullname = firstname + " " + lastname;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    THANK YOU!!! That made life so much easier but now it checks it, but loops anyway if you say no and it doesnt give the error messages
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int X;
        X=1;
        while(X=1)
        {
            string option;
            cout<<"Are you going to want to loop?\nYes or No: ";
            cin>>option;
            int Y;
            int Z;
            Y=0;
            while(Y>0)
            {
                Z=Y;
                if(option.length()<3)
                {
                    cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)";
                    Y++;
                }
                if(option.length()>4)
                {
                    cout<<"This isn't the time for buffer overflows yet";
                    Y++;
                }
                if(option.length()==4&&!(option=="yes"||option=="Yes"))
                {
                    cout<<"Tisk tisk, you tried to fool me by entering something the same size as yes, but not yes.\n";
                    Y++;
                }
                if(option.length()==3&&!(option=="No")||option=="no")
                {
                    cout<<"Tisk tisk, you tried to fool me by entering something the same size as no, but not no.\n";
                    Y++;
                }
                cout<<"That was your "<<Y<<" consecutive error, don't try to hack the non=hacking part";
                if(Y=Z)
                {
                       cout<<"Congrats, you had no error this time ;-)\n";
                       Y=0;
                }
            }               
            if (Y==0)//If there is no errors
            {
                if(option=="Yes"||option=="yes")
                {
                    char buffer[10];
                    cout<<"Ok, now try to overflow me\n";
                    cin>>buffer;
                    cout<<buffer;
                    cin.ignore();
                    cin.get();
                }
                if(option=="No"||option=="no")
                {
                    char buffer[10];
                    cout<<"Ok, now try to overflow me\n";
                    cin>>buffer;
                    cout<<buffer;
                    cin.ignore();
                    cin.get();
                    X=0;
                }
            }      
        }
        return 0;
    }

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Click on the Submit button only once, even if the page is really slow to load (as it's doing lately).

    Code:
    if(Y=Z)
    Use == for comparison.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    uuugh I want to tell it to display something if the text is as long as long but not "no"... maybe
    Code:
     if(option.length==2 && (option=!"No"||option=!"no"))
    Edit:Got it, but longer than what I had hoped fr


    Edit:Alright now I'm getting a F***ing "expected declaration before }" error message (on line 89(last line))
    And i dont know what it wants
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
        int V;
        int W;
        int X;
        int Y;
        int Z;
        string option;
        X=1;
        while(X=1)
        {
            cout<<"Are you going to want to loop?\nYes or No: ";
            cin>>option;
            Y=0;
            if(W==0)
            {
                W=1;
            }
            cout<<"\nThis is your "<<W<<" attempt\n";
            if(option.length()<2)
            {
                cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)\n";
                Z++;
                Y++;
                W++;
            }
            if(option.length()>3)
            {
                cout<<"This isn't the time for buffer overflows yet\n";
                Z++;
                Y++;
                W++;
                V=1;
            }
    
            if(option.length()==3)
            {
                if(option=="Yes"||option=="yes")
                {
                    char buffer[10];
                    if(V==1)
                    {
                        cout<<"Ok, Now is the time for overflowing me ^.^\n";
                    }
                    if(V==0)
                    {
                        cout<<"Ok, now overflow me\n";
                    }
                    cin>>buffer;
                    cout<<buffer;                    
                    }
                    else
                    {
                        cout<<"Tryin to trick me ey, thinkin your slick just putting the right amount in...noob\n";
                        W++;
                    }
                }
            }
            if(option.length()==2)
            {
                if(option=="No"||option=="no")
                {   
                    char buffer[10];
                    if(V==1)
                    {
                        cout<<"Ok, Now is the time for overflowing me ^.^\n";
                    }
                    if(V==0)
                    {
                         cout<<"Ok, now overflow me\n";
                    }
                    cin>>buffer;
                    cout<<buffer;
                    X=0;
                }
                else
                {
                    cout<<"Can't stand you, trying to trick me all the time...\n";
                    W++;
                }
            }
        }
    }
    Last edited by bikr692002; 02-28-2006 at 05:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  2. unwanted WM_TIMER
    By johny145 in forum Windows Programming
    Replies: 5
    Last Post: 06-27-2005, 11:21 AM
  3. How to get rid of an unwanted function return value?
    By RedZippo in forum C++ Programming
    Replies: 4
    Last Post: 03-22-2004, 02:42 PM
  4. Unwanted space inbetween characters
    By SAMSAM in forum Windows Programming
    Replies: 4
    Last Post: 01-25-2003, 11:41 PM
  5. removing an unwanted system folder
    By EvenFlow in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-22-2001, 03:04 AM

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