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.
Related
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;
}
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.
I have the following .c file:
/home/eamorr/project1/eamorr.c
I compiles fine and its exe is located at:
/home/eamorr/project1/a.out
Now, I have a php file at:
/home/eamorr/project1/a/b/c/eamorr.php
It needs to call a.out
<?php
$cmd=__DIR__."../../../a.out";
$result=`$cmd`;
?>
Here's the eamorr.c program:
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main (int argc, char *argv[]){
setuid (0);
char temp[2048];
char pwd[1024];
realpath(argv[0],pwd);
sprintf(temp,"/bin/bash %s/doMagic.sh",pwd);
system((char *)temp);
return 0;
}
Unfortunately the pwd variable contains the wrong path!!!
/home/eamorr/project1/a.out/doMagic.sh
How do I get rid of the a.out bit from the path? I don't program in C very often and I've been at this for over an hour now...
If I understand correctly, what you would like to get is something like:
/home/eamorr/project1/doMagic.sh
First of all, I dont generally do this kind of path handling in C. However, I had a quick look and it seems that you could use the dirname() functionality. Have a look here http://man7.org/linux/man-pages/man3/basename.3.html. Please be careful with this because I would imagine that these are Linux stuff, not sure how you would do it in DOS.
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");
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
system("PAUSE");
return 0;
}
After i Compiled the programme, i click run. it still tips me " project is not compiled" why? i am sorry, i am a new learner of c.
i am using dev c++, on xp, ctrl+F9 compile then ctrl+F10 run
it shows project is not compiled
multiple definition of main
Maybe in your project there is 2 Main function..
You should at least delete/change one..
if I see, there is 1-3.c and 1c.c
and the compile is error..
[Build Error]
CMIIW
Delete the file 1c.c. You cannot have two int main functions.