I am attempting to write a program that interfaces with Command prompt (simple, bring up a tasklist, user enters the program they want to get rid of, and then the computer does the rest), I already have been able to interface and bring up a tasklist, the code compiles with zero errors or warnings, however, when I enter the debug prompt, and put in the program I want to get rid of, command prompt, not the compiler comes up with the error "ERROR: Invalid syntax. Value expected for '/im'. Type "TASKKILL /?" for usage." I have already done several manual taskkills in regular command prompt, all of which with the same syntax.
tl;dr: Strcat doesn't put the second string where command prompt likes it
Here's the code, just for all of you to look it over:
#include <iostream>
#include <windows.h> //Includes command prompt
#include <string.h>
#include <string>
using namespace std;
int main()
{
char str [600];
char task1[20] = "tasklist";
char task2[20] = "color F9";
char task3[30];
int change1;
system (task2); // Changes the color by entering color F9 into CMD
cout << "Welcome to the CMD interface with C++ test!\n";
cout << "To begin testing, press one and then press ENTER.\n";
cout << "To change the color of this window, press two and then press ENTER.\n";
cout << "For help, press three and then press ENTER.\n";
cin >> ( change1 );
switch(change1) {
case 1: // begins the task killer
system(task1); // Enters Tasklist into CMD
cout << " " << endl;// gets an extra line of text between tasklist and the next line
cout << "This is a list of all of the tasks currently running by your computer.\n";
cout << "To stop running a program, please insert the FULL NAME (or the number next to\n";
cout << "the program) and then press ENTER\n";
cout << "WARNING: when the program is terminated, it WILL NOT save any of your data,\n";
cout << "please make sure that all of your data is saved before continuing!\n";
cin.getline (task3, 30);
cin.get ();
strcpy(str, "taskkill /f /im");
strcat(str, task3);
cout << "If you are sure you want to exit out of program";
cout << task3;
cout << ".\n Then please press Enter";
system (str);
cout << "\nPress ENTER to continue.";
cin.get ();
//case 2:
//I have yet to program this part onwards!
//default:
cout << "\nIncorrect entry, please try again.";
}
return 1;
}