Can some please tell me why this doesn't work because I just can't fingure it out.
Code:#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if ("help" == argv[1])
{
system("help.exe");
}
printf("%s\n",argv[1]);
}
Printable View
Can some please tell me why this doesn't work because I just can't fingure it out.
Code:#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if ("help" == argv[1])
{
system("help.exe");
}
printf("%s\n",argv[1]);
}
It does not work, or it won't compile? Be sure to check argc first.
Also return 0;
Logically, it should be:
if(argv[1] == "help")
However, you can't compare strings like that. Use strcmp().
Try this, though I dunno what the results will be or if it will work.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
if(argc == 2)
{
if((strcmp(argv[1], "help")) == 0)
printf("help was entered as an argument\n");
else
printf("%s was entered as an argument\n", argv[1]);
}
else
printf("no argument enetered, or more than one argument entered.\n");
return 0;
}