Code:
#include <cstdio>
#include <cstdlib>
#include <cstring>
int main(int argc, char **argv)
{
char *badsmell = NULL;
if (argc == 2)
{
int size = strlen(argv[1]);
badsmell = (char *)malloc(sizeof(char) * size);
strcpy(badsmell, argv[1]);
printf("%s\n", badsmell);
}
if (badsmell) free(badsmell);
return 0;
}
Of course this being C++, you could also do
Code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char **argv)
{
string badsmell;
if (argc == 2)
{
badsmell = argv[1];
cout << badsmell << endl;
}
return 0;
}