Click here to Skip to main content
Sign Up to vote bad
good
See more: C++CIDEEclipse
#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 26 Nov '12 - 6:42
Edited 26 Nov '12 - 6:55
ProgramFOX56.1K

Comments
lewax00 - 26 Nov '12 - 12:51
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:01
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:08
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:23
sorry i am new user of this site an i dont know much about asking question
Sergey Alexandrovich Kryukov - 26 Nov '12 - 13:38
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
ProgramFOX - 26 Nov '12 - 13:24
This isn't an answer to your question, but I found a bug. First, if I insert a very large number: 99999999999999999999999999 then I can insert another number. And if I enter this the second time: f then your program is repeating insert a.
ho_khalaf - 26 Nov '12 - 13:37
i chek my code in codebloks ide an work good.but in eclips it did not work
lewax00 - 26 Nov '12 - 15:05
I don't think there's much he can do about that, it's how scanf works. If you put in a number that large it rolls over into negatives (of course he could check for numbers less than 0, but maybe he wants to allow negative numbers).

3 solutions

i was missing a flush.
 
This works:
 
...
printf("insert a");
fflush(stdout);
scanf("%d",&a);
...
See also "[SOLVED] No Output in Console"
http://www.eclipse.org/forums/index.php/t/156519/[^]
  Permalink  
Comments
Albert Holguin - 26 Nov '12 - 22:41
Sounds like a bug w/ the IDE... well, at least you found a workaround.
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
  Permalink  
Comments
ProgramFOX - 26 Nov '12 - 13:18
+5!
Sergey Alexandrovich Kryukov - 26 Nov '12 - 13:36
Thank you. --SA
Albert Holguin - 26 Nov '12 - 22:43
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"[^].
  Permalink  
Comments
ho_khalaf - 26 Nov '12 - 14:28
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:26
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:40
yes but did not work
CPallini - 26 Nov '12 - 15:43
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:50
when i execute the executable file it work good as my expect but in eclipse ide did not work.
CPallini - 26 Nov '12 - 16:06
Then is just a problem of your IDE. I won't bother too much. (If you really bother then you may try to ask at Eclipse specific forums)
ho_khalaf - 26 Nov '12 - 16:08
thank you very much
CPallini - 26 Nov '12 - 16:22
You are welcome.
ho_khalaf - 26 Nov '12 - 17:43
i ask it in eclipse.org community and get this answer: "printf("insert a"); fflush(stdout);scanf("%d",&a);".it was good and worked. thank you again.
CPallini - 26 Nov '12 - 18:02
Oh, my bad, in my suggestion I wrote stdin instead of stdout, sorry for the inconvenience! By the way, I am it eventually worked.
ho_khalaf - 26 Nov '12 - 18:07
no problem you do best job as you can.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 498
1 Arun Vasu 275
2 Maciej Los 273
3 Mahesh Bailwal 264
4 Aarti Meswania 175
0 Sergey Alexandrovich Kryukov 9,660
1 OriginalGriff 7,329
2 CPallini 3,968
3 Rohan Leuva 3,339
4 Maciej Los 2,851


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid