Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

What is the problem with my void function? I started it like scanf... then printf the character the format is correct but what the hell is the problem?

OpenStudy (anonymous):

Pls show us your whole code of void function.

OpenStudy (anonymous):

I somehow changed it. void askuser() { char p; gotoxy(5,10); printf("Do you want to continue?"); gotoxy(5,11); printf("<Y//N>"); gotoxy(5,12); scanf("%c",&p); gotoxy(5,13); printf("%c",p); }

OpenStudy (anonymous):

I think you are having problem with gotoxy() function, make sure if you included its library in the header.

OpenStudy (anonymous):

No the gotoxy is fine it has its own function

OpenStudy (anonymous):

Any unexpected behavior ?

OpenStudy (anonymous):

When the part the scanf must play it only says Press any key to continue thus skipping the printing the character scanned part.

OpenStudy (anonymous):

But when i compile without gotoXY, it compiles and runs as you say in my g++. Pls tell what you want to do ?

OpenStudy (anonymous):

I just want to know why does my program stops at the scanf?

OpenStudy (anonymous):

Which compiler ? I don't think it should stop.

OpenStudy (anonymous):

Of course it stops in scanf, because scanf means "wait the user to enter something from the keyboard".

OpenStudy (anonymous):

LOL i didn't noticed scanf, totally forgot it. @ktobah is right. It'll wait till you put any char for input.

OpenStudy (anonymous):

No it totally stopped. I expected for it to wait for an input but it said Press any key to continue...

OpenStudy (anonymous):

Tell me please, which library you include so your compiler reconize : gotoxy() ?

OpenStudy (anonymous):

I suspect that gotoXY is moving the location of input stream, hence it reading char automatically at 5,10 location on screen, Thus, not letting you to type anything.

OpenStudy (anonymous):

I found that it's in <conio.h> but it isn't standard so please don't use it, if not required.

OpenStudy (anonymous):

I used conio.h, but the compiler didn't recognize it !!!

OpenStudy (anonymous):

#include<conio.h>???

OpenStudy (anonymous):

it depends on the compiler I think

OpenStudy (anonymous):

I did that yes, and yes I think it depends on the compiler, I'm using Dev-C++, and I commented the portion of gotoxy on your code and I tried it and it works well.

OpenStudy (anonymous):

You, so which compiler you have ?

OpenStudy (anonymous):

Can we go back to my question why does it stop when it came upon the scanf????

OpenStudy (anonymous):

void gotoxy(int x, int y) { static HANDLE h = NULL; if(!h) h = GetStdHandle(STD_OUTPUT_HANDLE); COORD c = { x, y }; SetConsoleCursorPosition(h,c); }

OpenStudy (anonymous):

void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); }

OpenStudy (anonymous):

what is the difference between the two????

OpenStudy (anonymous):

I tried with this code : void gotoxy(int x, int y) { static HANDLE h = NULL; if(!h) h = GetStdHandle(STD_OUTPUT_HANDLE); COORD c = { x, y }; SetConsoleCursorPosition(h,c); } inside your program and it works well.

OpenStudy (anonymous):

Nothing. Both are same.

OpenStudy (anonymous):

How suppose am I to solve my problem regarding the input of the variables???

OpenStudy (anonymous):

I suggest that before defining your void function "askuser", first define gotoxy(), just copy and paste this code there then try to recompile your program and run it, then see the result.

OpenStudy (anonymous):

its stops in the scanf part

OpenStudy (anonymous):

Can you show me your main program (the code) ?

OpenStudy (anonymous):

May I show you the whole code its my project xD

OpenStudy (anonymous):

no no, I just wanted to see how you call your void function inside your main program. Look I tried this code and it works : #include<stdio.h> #include<windows.h> void gotoxy(int x, int y) { static HANDLE h = NULL; if(!h) h = GetStdHandle(STD_OUTPUT_HANDLE); COORD c = { x, y }; SetConsoleCursorPosition(h,c); } void askuser() { char p; gotoxy(5,10); printf("Do you want to continue?"); gotoxy(5,11); printf("<Y//N>"); gotoxy(5,12); scanf("%c",&p); gotoxy(5,13); printf("%c",p); } int main(){ askuser(); }

OpenStudy (anonymous):

what is your compiler???

OpenStudy (anonymous):

I'm using Dev-C++

OpenStudy (anonymous):

really??? does it work??? xD thanks

OpenStudy (anonymous):

haha yes, it works, did it work for you ?

OpenStudy (anonymous):

I have not tried it yet

OpenStudy (anonymous):

Ah ok, good luck then.

OpenStudy (anonymous):

Can you teach me pointers?

OpenStudy (anonymous):

Ops sorry @LemuelPogi I really have a research to complete also I'm not that good in pointers. Excuse me!

OpenStudy (anonymous):

okey thanks for the help.

OpenStudy (anonymous):

Ah You're welcome.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!