|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char again;
do{
printf("insert y or Y to repeat");
fflush(stdout);
scanf("%c",&again);
}while(again=='y'||again=='Y');
}
i wrote this code to create a loop that when insert y or Y do the job again but did not work.when i enter first y the loop be end.
|
|
|
|
|
As mentioned in the QA section: Please don't cross post. I decided to answer you here.
Did you take a look at "again" in the debugger? You will recognize that in the second round thru the loop it will have the value 0x0a == \r it's the carriage return from your input.
You can try something like this to catch the CR:
char cr;
char again;
do
{
printf("insert y or Y to repeat");
fflush(stdout);
again = getchar();
cr = getchar();
}while(again=='y'||again=='Y');
|
|
|
|
|
thank you very much Andy411.its work good.
what do you use
cr = getchar();
what do this code
|
|
|
|
|
How do you learn C? Don't you have a book or a tutoroial with an index?
That's what google answered me:
http://www.cplusplus.com/reference/cstdio/getchar/[^]
PS: Sorry if my answer sounds a bit rude, but I am realy confused about the question what getchar does. If I were you, my first step would be asking google, bing are whatever searchmachine you want. Or taking a look inside a book. If I don't understand the description/answer there, I would ask in a forum again.
|
|
|
|
|
run your code ,you will get the result.
"insert y or Y to repeatY insert y or Y to repeat"
then code end.
it is useless.
fflush(stdout);
you can write
fflush(stdin);
|
|
|
|
|
is there any body work with eclipse c\c++ ide ?
I write this code in eclipse C\C++ IDE but did not work.
its work in codeblocks bud didnt work in eclipse c++ ide.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a=100;
do{
printf("insert a");
scanf("%d",&a);
}while(a<10);
return (0);
}
|
|
|
|
|
what is not working ? compile error ? execution error ?
Nihil obstat
|
|
|
|
|
it compile but the console tab did not show any thing.and when i push the stop button and stop the project just show "insert a" and stop.
|
|
|
|
|
This is the third time you have posted this question. Please stop repeating yourself.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i write this cod in eclipse c\c++ ide but did not work.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a=100;
do{
printf("insert a");
scanf("%d",&a);
}while(a<10);
return (0);
}
|
|
|
|
|
What didn't work?
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
I just tested it and it works fine.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
sorry you test it in eclipse c\c++ ide?
|
|
|
|
|
Well I see you already got an answer in Q&A. Please do not post questions in more than one forum in future.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
|
i use eclipse newly but this code did not work in this ide
|
|
|
|
|
Please stop repeating yourself and go and read the information that CPallini provided to resolve this issue.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i rad it befor and i know that eclips did not show the console.but eclips have console tab and in that tab did not show any thing.
|
|
|
|
|
Go to the eclipse website and ask there.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
This is not a C/C++/MFC question, but an Eclipse question.
Doesn't Eclipse also have an Output tab?
Part of the problem may be that you do not have a \n in the output stream. You might try that and/or calling fflush() after the call to printf() . Calling setbuf() might also be a consideration.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 26-Nov-12 16:52pm.
|
|
|
|
|
no i cant find it if you can pleas say to me
|
|
|
|
|
i ask it in eclipse.org forum and this is the answer:
"
printf("insert a");
fflush(stdout);
scanf("%d",&a);
|
|
|
|
|
What about:
printf("insert a: \n");
scanf("%d", &a);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
printf("insert a");
fflush(stdout);
scanf("%d",&a);
just this code work.and solve the problem
|
|
|
|
|
Dear Community,
I'm using C++ to develop a small Bootstrapper (Setup.exe) application in C++. Using CreateProcess() to launch a .hta (HTML Application) which is used as a UI. It then calls other installers one by one which includes *.exe, *.msi etc.
What I'm trying to do is if I execute my Setup.exe, it asked for UAC for once and launch .hta so that it doesn't required UAC any further. Here is my code:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( CreateProcess(NULL, "C:\\Windows\\MsHta.exe SetupGUI.hta" ,
NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
{
WaitForSingleObject(pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
I actually saw same in an application installer, but I don't have its Setup.exe's source code.
Thanks a lot.
Farrukh
|
|
|
|