I’m trying to make a program that finds the largest prime factor of a given value.
If I run ./a.out 55, cout << "Input " << *argv[1]<< endl; returns 5 instead of 55.
When I take out the asterik and check the pointer `value(argv[1]) I get 55. I’m confused why this is happening.
int main(int argc, char *argv[])
{
if(argc == 2)
{
cout << "Input " << *argv[1]<< endl;
// cout << "Biggest Prime Factor of 34 is : " << findPrime(number, 0) << endl;
}
else
cout << "Too many inputs:" << endl;
return 0;
}
Drop the
*:It’s because
*argv[1]means the first character ofargv[1]. You want the entire string instead.