I want to make a program in c that compiles and runs another program. I wrote this code and it returns this:
robi@Robi:~$ ./comp test.c
gcc: fatal error: no input files
compilation terminated.
Error
I compile it like this:
gcc -Wall -o comp Compilare.c
and run it like this:
./comprun test.c
test.c is this
#include<stdio.h>
int main(){
printf("Ana are mere");
return 0;
}
The code:
#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
int main(int argc,char* argv[]) {
char comanda[100];
strcpy(comanda,"gcc -o run");
strcat(comanda,argv[1]);
if(WEXITSTATUS(system(comanda) == 0))
execl("./run","./run",NULL);
printf("Error");
return 0;
}
How can I make it run without errors?
runinstrcpy- Erik Wgcc -o runtest.cinstead ofgcc -o run test.c. Just add the space and it should be fine. - that other guyprintf("Ana are mere");will only output to thestdoutbuffer, You want output through that buffer to the display, so the line should be:printf("Ana are mere\n");orprintf("Ana are mere"); fflush( stdout );- user3629249