Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_CHARS 256
  5.  
  6. int main()
  7. {
  8. char command[MAX_CHARS] = {0};
  9. char programToCompileAndRun[MAX_CHARS] = {0};
  10.  
  11. printf("Files on this folder:\n");
  12.  
  13. system("dir");
  14.  
  15. printf("What program would you like to compile? ");
  16.  
  17. fgets(programToCompileAndRun, MAX_CHARS, stdin);
  18.  
  19. if(programToCompileAndRun[strlen(programToCompileAndRun) - 1] == '\n') //Making sure that ENTER won't be part of our string.
  20. {
  21. programToCompileAndRun[strlen(programToCompileAndRun) - 1] == '\0'
  22. }
  23.  
  24. sprintf(command, "gcc -o %s.exe %s.c", programToCompileAndRun); //Building the compiling command.
  25.  
  26. system(command); //Compiling the program.
  27.  
  28. sprintf(command, %s, programToCompileAndRun); //Building the running command.
  29.  
  30. system(command); //Running the program.
  31.  
  32. return 0;
  33. }
Add Comment
Please, Sign In to add comment