Click here to Skip to main content
15,883,990 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int a=100;
    do{
        printf("insert a");
        scanf("%d",&a);
    }while(a<10);
    return (0);
}


I write this code in eclipse C\C++ IDE but did not work.

[Edit]Language of code block changed[/Edit]
Posted
Updated 26-Nov-12 6:55am
v2
Comments
lewax00 26-Nov-12 12:51pm    
What do you mean "did not work"? Did it fail to compile, or did it not do what you expected it to do? You need to add some more details.
ho_khalaf 26-Nov-12 13:01pm    
it compile but did not do any thing.when i stop the program just print insert a.and when i run it again the console tab is empty.
Sergey Alexandrovich Kryukov 26-Nov-12 13:08pm    
Why would you toss everything in one pile: C++, IDE, Eclipse? Ever heard of separation of concerns? Do I have to report it as off-topic? Do you have an idea why? This is a site for software developers (and students). A software developer does not say "not working" but provides a comprehensive issue report. There are some minimal prerequisites for asking questions here.
--SA
ho_khalaf 26-Nov-12 13:23pm    
sorry i am new user of this site an i dont know much about asking question
Sergey Alexandrovich Kryukov 26-Nov-12 13:38pm    
No need to apologize. Just think logically. This is not formality but a way of approaching problems. Know your development cycle; learn every detail on every of your tools: what does what. Anyway, I answered.

Good luck.
--SA

Not true. It actually does something: first iteration of the loop is always executed, at least one "insert a" outputs to console (if one is available; it depends on project configuration), others depend on what value for a you are entering. Of course, the code makes little to no sense — you need tell us what did you want to achieve first.

—SA
 
Share this answer
 
Comments
Thomas Daniels 26-Nov-12 13:18pm    
+5!
Sergey Alexandrovich Kryukov 26-Nov-12 13:36pm    
Thank you.
--SA
Albert Holguin 26-Nov-12 22:43pm    
Think he just found a little "undocumented feature" in Eclipse.... but no, I don't see why he would want to do a loop like that either, but maybe it was just a test program...
If you are working on Windows then this may interest you: "Eclipse console does not show output on Windows"[^].
 
Share this answer
 
Comments
ho_khalaf 26-Nov-12 14:28pm    
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.
CPallini 26-Nov-12 15:26pm    
Did you try, as suggested in the page I linked, to call fflush(stdin); fflush(stdout); immediately after the printf statement?
ho_khalaf 26-Nov-12 15:40pm    
yes but did not work
CPallini 26-Nov-12 15:43pm    
You may try also to launch your executable directly (instead of letting Eclipse doing that for you): find where your executable is and run it from the command shell.
ho_khalaf 26-Nov-12 15:50pm    
when i execute the executable file it work good as my expect but in eclipse ide did not work.
i was missing a flush.

This works:

C++
...
printf("insert a");
fflush(stdout);
scanf("%d",&a);
...

See also "[SOLVED] No Output in Console"
http://www.eclipse.org/forums/index.php/t/156519/[^]
 
Share this answer
 
v2
Comments
Albert Holguin 26-Nov-12 22:41pm    
Sounds like a bug w/ the IDE... well, at least you found a workaround.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900