c_cpp 比较2个字符串,如果它们相等

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 比较2个字符串,如果它们相等相关的知识,希望对你有一定的参考价值。

int stringEqual(char* str1, char* str2){
  const char* p1 = str1;
  const char* p2 = str2;
  while(*p1 == *p2){
    if(*p1 == '\0'){
      return 1;
    }    
    //advance p1 and p2 to point at the next letter
    p1++;
    p2++;
  }  
  return 0;
}

以上是关于c_cpp 比较2个字符串,如果它们相等的主要内容,如果未能解决你的问题,请参考以下文章