C string problem

This code works on my desktop tower using windows 7 DEV C++, but does not work on my Toshiba laptop in windows 8. If I enter alan the results are >>@#%<<. Charcters work and integers work, but strings do not.

int main(void)
int x;
double y;
char string[100];

/* string input */
printf("enter one word: ");
scanf("%s", string); /* no & before string */
printf("The word you entered was >>%s<<\n");

Please use code tags whenever posting your code.


In C note that int main(void) and int main() are not the same thing.

Use that in C++ code and you'll get some guys on here scolding the hell out of you. chrisname! cough* cough*

Do not use Bloodshed Dev C++. It's bad, period. Use Code::Blocks if you you're going for a free opensource compiler.

What's the point of int x and int y ? You declare them but they aren't used anywhere.

I'm not really a C guy, so someone else correct me if I'm wrong, but is fflush(stdin); necessary the first time? I honestly don't know about that.

Lastly, what compiler are you using on your laptop?
Using the same compiler, so that's probably the problem. Your correct fflush(stdin); is not necessary.
Isn't there something missing here?
printf("The word you entered was >>%s<<\n"); // which string?

By the way, Orwell Dev C++ is ok to use, it is up to date.
It worked on my desktop so I didn't catch it.

That fixed it. Thanks
Topic archived. No new replies allowed.