-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunchProgram.c
More file actions
30 lines (27 loc) · 942 Bytes
/
launchProgram.c
File metadata and controls
30 lines (27 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Program to compile and execute a c program
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_COMMAND_SIZE 500
char commandString[MAX_COMMAND_SIZE];
int main(int argc, char const *argv[])
{
char objectFolder[] = "~/gcc/";
char *fileName = (char *)malloc(sizeof(argv[1]));
strcpy(fileName, argv[1]);
char *objectFileName = (char *)malloc(sizeof(fileName));
strncpy(objectFileName, fileName, strlen(fileName)-2);
strcat(commandString, "g++ ");
strcat(commandString, fileName);
strcat(commandString, " -o ");
strcat(commandString, objectFolder);
strcat(commandString, objectFileName);
strcat(commandString, " && chmod 755 ");
strcat(commandString, objectFolder);
strcat(commandString, objectFileName);
strcat(commandString, " && ./");
strcat(commandString, objectFolder);
strcat(commandString, objectFileName);
system(commandString);
return 0;
}