Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX_CHARS 256
- int main()
- {
- char command[MAX_CHARS] = {0};
- char programToCompileAndRun[MAX_CHARS] = {0};
- printf("Files on this folder:\n");
- system("dir");
- printf("What program would you like to compile? ");
- fgets(programToCompileAndRun, MAX_CHARS, stdin);
- if(programToCompileAndRun[strlen(programToCompileAndRun) - 1] == '\n') //Making sure that ENTER won't be part of our string.
- {
- programToCompileAndRun[strlen(programToCompileAndRun) - 1] == '\0'
- }
- sprintf(command, "gcc -o %s.exe %s.c", programToCompileAndRun); //Building the compiling command.
- system(command); //Compiling the program.
- sprintf(command, %s, programToCompileAndRun); //Building the running command.
- system(command); //Running the program.
- return 0;
- }
Add Comment
Please, Sign In to add comment