Reputation: 155
I have three c files one.c, two.c and three.c on Linux in same folder I need to first run one.c file and then as soon as it completes running it should automatically run two.c file. After two.c file completes running it should automatically run three.c and so on...
All the files will be compiled.
Thanks in advance !!! !! !
Upvotes: 1
Views: 246
Reputation: 3642
You could compile and run them separately, like jightuse and mbratch suggest in the comments. Another approach to "running" each one, would be to link them together and run a function from each. Here, I've changed main() to main1(), main2(), and main3(), but in separate files.
poly@blue-starling ~/junk/2013.11: cat one.c
#include <stdio.h>
void main1(void)
{
printf("one here!\n");
}
poly@blue-starling ~/junk/2013.11: cat two.c
#include <stdio.h>
void main2(void)
{
printf("two here!\n");
}
poly@blue-starling ~/junk/2013.11: cat three.c
#include <stdio.h>
void main3(void)
{
printf("three here!\n");
}
poly@blue-starling ~/junk/2013.11: cat main.c
void main(void)
{
main1();
main2();
main3();
}
poly@blue-starling ~/junk/2013.11: gcc *.c
main.c: In function ‘main’:
main.c:2: warning: return type of ‘main’ is not ‘int’
poly@blue-starling ~/junk/2013.11: a.out
one here!
two here!
three here!
poly@blue-starling ~/junk/2013.11:
(It's broken some rules and gotten a warning, since the main()
isn't strictly a proper main, but hopefully shows the idea.)
Anyway, that's one way.
Upvotes: 1