help, C problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Ratstail91
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Sun Feb 01, 2009 1:58 am

help, C problem

Post by Ratstail91 »

Hello. I'm experienced in Game maker, but Im just starting to learn C.
my problem is, when I use a function, it works once, and then doesn't work again until i call main() and even then, other input fields don't work. it writes the string I put into the "continue" field into the "name"field.

I know this is confusing, but if anyone can help, it would be appreciated. here is the code.

int wait();

...

int wait()
{
char n;
printf("\ncontinue (y)?");
scanf("%d",n);
}

...
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: help, C problem

Post by wtetzner »

Could you post your main() function too? Also, you need to return an int from wait(), or change it to void wait().
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: help, C problem

Post by MarauderIIC »

http://www1.coe.neu.edu/~emelas/char.html might help you. In short, try changing your call to

Code: Select all

scanf("%c%*c", &n);
since you're reading a character.

Edit: Fixed, thanks sparda.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
sparda
Chaos Rift Junior
Chaos Rift Junior
Posts: 291
Joined: Tue Sep 23, 2008 3:54 pm

Re: help, C problem

Post by sparda »

you use scanf("%c%*c", &n);

not scanf("%c%*c", n);

*Fixed*
User avatar
Ratstail91
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Sun Feb 01, 2009 1:58 am

Re: help, C problem

Post by Ratstail91 »

Not a clue what anyone is talking about. however i think I figured it out. now... to write a program that actually does what i tell it too!
Post Reply