Trying to clone the "yes" command using C++ as a little experiment (this is on Ubuntu 12.10), and there's a little problem here:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
void yes (char* cmd[]) {
if ( cmd != NULL ) {
while (true) {
cout << cmd[1] << endl;
}
} else {
while (true) {
cout << "y" << endl;
}
}
}
int main(int argc, char** argv[]) {
yes(argv[1]);
return 0;
}
If I leave it as is, I get the warning as described in the title. If I remove one of the asterisks on argv, I get an error about converting "char*" to "char**". And removing the extra function (i.e. putting it all in main, like so):
int main(int argc, char** argv) {
if ( argv != NULL ) {
while (true) {
cout << argv[1] << endl;
}
} else {
while (true) {
cout << "y" << endl;
}
}
return 0;
}
makes no difference about the warning.
Thanks in advanced...