Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,211 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 920 people online right now. Registration is fast and FREE... Join Now!




Really Simple IO Problem

 
Reply to this topicStart new topic

Really Simple IO Problem

Beeeph
post 14 Mar, 2008 - 04:16 PM
Post #1


New D.I.C Head

*
Joined: 10 Mar, 2008
Posts: 9

For some reason, this very simple code doesn't read in the very first character...

CODE

char strScenario[80] = {0};

cout << "Enter name of scenario" -->;
gets(strScenario);


if I type in "scenario01" in the console window, the data inside strScenario after this code is "cenario01", it's missing the first character. I've tried many different variations of this code, such as...

CODE

char strScenario[80] = {0};

cout << "Enter name of scenario" -->;
cin.getline(strScenario, 80);



CODE

char strScenario[80] = {0};

cout << "Enter name of scenario" -->;
cout.flush();
cin.getline(strScenario, 80);


and they all produce the same results, the first character is missing. Why?!?

and when i do this...

CODE

char strScenario[80] = {0};

cout << "Enter name of scenario" -->;
cin >> strScenario;


i get "ar" as the data.

any ideas? Thanks in advance!

Beeeph
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 14 Mar, 2008 - 04:33 PM
Post #2


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


cout << "Enter name of scenario" -->;

to

cout << "Enter name of scenario -->";

see the difference :)
User is offlineProfile CardPM

Go to the top of the page

Beeeph
post 14 Mar, 2008 - 04:43 PM
Post #3


New D.I.C Head

*
Joined: 10 Mar, 2008
Posts: 9

QUOTE(letthecolorsrumble @ 14 Mar, 2008 - 05:33 PM) *

cout << "Enter name of scenario" -->;

to

cout << "Enter name of scenario -->";

see the difference smile.gif



sorry, that was just a typo when I was writing this post. Obviously the code wouldn't have compiled if that were the actual code and I wouldn't be experiencing weird run-time bugs because the program wouldn't run in the first place. Sorry about that mistake.

Any other ideas?
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 14 Mar, 2008 - 05:06 PM
Post #4


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


CODE

int main() {
        

    char strScenario[80] = {0};

    cout << "Enter name of scenario -->";
    gets(strScenario);

    cout << strScenario << endl;

    return 0;

}


This code is working fine. It is the same that you have posted one the top.


The Output:
CODE

Enter name of scenario -->scenario01
scenario01
Press any key to continue


*edit: So I hope that the problem is just your compiler, or computer, otherwise it would be really weird.

This post has been edited by letthecolorsrumble: 14 Mar, 2008 - 07:24 PM
User is offlineProfile CardPM

Go to the top of the page

Beeeph
post 14 Mar, 2008 - 05:28 PM
Post #5


New D.I.C Head

*
Joined: 10 Mar, 2008
Posts: 9

QUOTE(letthecolorsrumble @ 14 Mar, 2008 - 06:06 PM) *

CODE

int main() {
        

    char strScenario[80] = {0};

    cout << "Enter name of scenario -->";
    gets(strScenario);

    cout << strScenario << endl;

    return 0;

}


This code is working fine. It is the same that you have posted one the top.


The Output:
CODE

Enter name of scenario -->scenario01
scenario01
Press any key to continue



I know the code is structured fine and, as such, should work fine. I guess what I'm asking, does anyone have any ideas why this problem might be occurring on my machines and, if so, how it might be fixed. Thanks.

Beeeph
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 08:11PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month