i'm trying to pass arguments into main through the command line and then compare string in argv[1] with some strings in code. It doesn't work, always block else is executed even if i type exactly the same string! What's wrong?
#include <iostream>
#include <string.h>
using namespace std;
int main(int argc, char * argv[])
{
if (argc>2)
{
if (strcmp(argv[1], "ball ")==0)
{...}
else if (strcmp(argv[1], "dance ")==0)
{...}
else
{
cout<<"Ops"<<endl;
cout<<argv[2]<<endl;
cout<<argv[1]<<endl;
}
Aucun commentaire:
Enregistrer un commentaire