Print statement not working on CodeBlocks for Mac - c

I've recently downlaoded code blocks for mac and for some reason my code compiles with no errors but when I try to run it in terminal to see if it prints it doesn't print anything. This is my code. I have already downloaded x code and my program is able to build in code blocks but print f will not work. Can someone please give a solution to this problem.
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}

Related

Why does my code keep failing in codeblocks?

Here's the code I wrote.
#include <stdlib.h>
#include <stdio.h>
int main(void){
printf("hello World.");
return 0;
}
This is the error message
Execution of '"C:\Users\Happy Birthday\Desktop\Coding\C++\C_C++ project\simple program.exe"' in 'C:\Users\Happy Birthday\Desktop\Coding\C++\C_C++ project' failed.|
I figured it out. I had to go to the location of the bin for MinGW, copy and paste its address into the Toolchain executables tab of the global compiler settings, as opposed to auto detecting it.

"Hello world" program not running

I typed this program on code blocks but it is showing error on int main line
Here's the program
#include <stdio.h>
int main()
{
printf("Hello");
return 0;
}
The message return is " multiple definition of main"
The sample code is correct. It might be an IDE configuration error. Use gcc to compile your code on Linux and on Windows you can install MinGW and execute from a command window.

Simple C code prints nothing to terminal

I ran a 4 line code and it compiled and linked without a hitch, but it refuses to print anything
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char* a = "book";
printf("%s\n", a);
return 0;
}
After compiling it and running the executable, nothing happens.
No error in the code.
Just write getch(); or getchar() before return 0;
to holding the output screen.
getch() or getchar() will hold the ouput screen for getting the user's input.
Works fine for me.
You've tagged this with terminal; if you are running it from the terminal, you should see some output, in my experience.
If you are running from an IDE,
keep the window open using Kapil K.'s answer;
keep the window open using an IDE setting, if there is one; or
find out where your IDE is putting the executable file, and run that from a terminal.

Seeing the output of my program

I am having a problem with a program of mine, as I cannot see the output display. Using a Dev C++ compiler to compile my C program, I debug it to see the output. However my program immediately terminates, so I can't see the output properly.
I ended my program with return 0, and Aldo tried getch(), but even with both endings my program terminates quick.
I want to know if my program endings are wrong, and if so what is the correct way to end a program?
you need the window stop to view the output, is it right?
if yes, include this library
#include <stdlib.h>
then add this line at the end of code:
system("PAUSE");
e.g
#include <stdlib.h>
#include <stdio.h>
int main()
{
/* do/print some thing*/
system("PAUSE");
}

Compiling C program in NetBeans 7

I have a problem with netbeans 7 about debugging and running C program, the problem is that after I wrote the code as the following
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("done");
"khaled";
return 0;
}
in the output panel everything goes well but there's not any real output project (excutable file) no window appears.
I use gcc complier as the C compiler.

Resources