在C上比较字符串和if

Jos*_*lau -2 c string if-statement numbers

我需要创建一个比较字符串并为字符串分配数字的代码.我这样做了:

int metd=0;
if (strcmp( metodo, "GET")==1){
    metd=1;
}
if (strcmp( metodo, "HEAD")==1){
    metd=2;
}
if (strcmp( metodo, "PUT")==1){
    metd=3;
}
if (strcmp( metodo, "DELETE")==1){
    metd=4;
}
Run Code Online (Sandbox Code Playgroud)

但最后,metd总是4.有些想法?

Gop*_*opi 5

0当两个字符串相同时,strcmp()返回1