Click here to Skip to main content
13,197,200 members (58,315 online)
Rate this:
Please Sign up or sign in to vote.
See more:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    int a=100;
        printf("insert a");
    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:42am
Updated 26-Nov-12 6:55am
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.
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.
ProgramFOX 26-Nov-12 13:24pm
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:37pm
i chek my code in codebloks ide an work good.but in eclips it did not work
lewax00 26-Nov-12 15:05pm
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).
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

ProgramFOX 26-Nov-12 13:18pm
Sergey Alexandrovich Kryukov 26-Nov-12 13:36pm
Thank you.
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...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you are working on Windows then this may interest you: "Eclipse console does not show output on Windows"[^].
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.
CPallini 26-Nov-12 16:06pm
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:08pm
thank you very much
CPallini 26-Nov-12 16:22pm
You are welcome.
ho_khalaf 26-Nov-12 17:43pm
i ask it in 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:02pm
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:07pm
no problem you do best job as you can.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

i was missing a flush.

This works:

printf("insert a");

See also "[SOLVED] No Output in Console"[^]
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100