#include #include using namespace std; //hasHelpOption() definition int hasHelpOption(int argc, char **argv) { for(int i=0;i
#include <iostream>
#include <string.h>
using namespace std;
//hasHelpOption() definition
int hasHelpOption(int argc, char **argv)
{
for(int i=0;i<argc;++i)
if(((strcmp(argv[1],"--help"))==0) || ((strcmp(argv[1],"/help"))==0) || ((strcmp(argv[1],"/?"))==0))
return 1;
else
return 0;
}
//main function
int main(int argc, char** argv)
{
int x=0;
cout << "You have entered: "<<argv[1];
x=hasHelpOption(argc,argv);
if(x==1)
cout<<"\nTrue";
else
cout<<"\nFalse";
return 0;
}
what should i correct for the code?
Your program gives the following warning on compilation:
It is because the compiler can not tell that if the function will return something. Because in a scenario of variable 'argc' having a value equal to less than 0, 'for' loop will never run and the compiler doesn't know what return. You have to make sure that the program is returning a value irrespective of conditional statements.
Step by step
Solved in 2 steps with 3 images