Using the equality operator == to compare two strings for equality in C

前端 未结 9 696
悲&欢浪女
悲&欢浪女 2020-11-22 16:38
int main (int argc, **argv)
{
       if (argv[1] == \"-hello\")
            printf(\"True\\n\");
       else
            printf(\"False\\n\");
}
         


        
9条回答
  •  梦谈多话
    2020-11-22 17:23

    Strings are not native types in C. What you are comparing in that example are two pointers. One to your first argument, and the other is a static character array with the contents of "-hello".

    You really want to use strncmp or something similar.

提交回复
热议问题