Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing argv char to a string

Status
Not open for further replies.

alias301reader

Programmer
Jan 5, 2009
2
0
0
I am trying to do this:

#include <iostream>
#include <string>
#include <cstring>

int main (int argc, char *argv[])
{
// this is were the problem is I keep getting this:
// invalid conversion from ‘char’ to ‘const char*’
// initializing argument 1 of ‘int strcmp(const char*, const char*)’
if (strcmp(argv[1][1], "y") == 0){
std::cout << "Yes" << std::endl;
} else {
std::cout << "No" << std::endl;
}
return 0;
}
 
argv[1] is a char*, so
Code:
if ( strcmp(argv[1], "y") == 0 )

argv[1][1] is a char, so
Code:
if ( argv[1][1] == 'y' )

PS
Please use code tags.



--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top