0

Heya I have installed codeblocks..on windows7 codeblocks-13.12mingw-setup-TDM-GCC-481.exe my program is building but after executing i am getting a console window only with a cursor and no output. I tried it with many other programs but the same thing is happening. I have also set all the settings to default and have also re installed codeblocks. I am attaching snippet of the console window for the program code:

#include <stdio.h>

int main()
{
   printf("helloworld%s")
   return 0;
 }

Even the default program was not working because it failed to recognize iostream. PLease help..!

fvu
  • 32,488
  • 6
  • 61
  • 79
varshika03
  • 71
  • 3
  • 1
    How about removing `%s` ? – Leśny Rumcajs Dec 23 '15 at 11:40
  • 2
    1 - that code won't even compile due to the missing `;` after the printf line (and no compilation, no execution and thus no output so that might be your first problem), but even if it would compile 2 - `"helloworld%s"` is invalid as you fail to pass an extra string argument – fvu Dec 23 '15 at 11:41
  • you can `#include ` and print `std::cout << "helloworld" << std::endl;` – gomons Dec 23 '15 at 11:41
  • @BoPersson yes i use avast antivirus but i tried to execute by switching it off temporarily still no help! – varshika03 Dec 25 '15 at 08:20
  • @fvu thanks for it i removed%s and also put a semicolon still it compiled but didn't show output! – varshika03 Dec 25 '15 at 08:21
  • @gomons compiler is failing to recognise iostream thereby i shifted to stdio.h – varshika03 Dec 25 '15 at 08:22
  • "compiler is failing to recognize iostream" - is your file called somethign ending in `.cpp` ? – M.M Dec 25 '15 at 11:36

1 Answers1

1
  1. You forgot the ; at the end of the printf() line, you should have a syntax error when compiling.

  2. The %s doesn't mean any sense if there is no additionnal argument. It is used when you want to print a string stored in a variable. Example:

int main(int argc, char** argv) { char str[] = "world!"; printf("Hello %s\n", str); }

will print "Hello world!".

  1. Unless you know what you're doing, you should add a \n at the end of the printed line (before output on stdout are buffered, and printed when the buffer is full : Is stdout line buffered, unbuffered or indeterminate by default?)
Community
  • 1
  • 1
Pierre
  • 1,162
  • 12
  • 29