C語言字符篇(三)字符串比較函數


#include <string.h>  
int strcmp(const char *s1, const char *s2);

比較字符串s1和s2

int strncmp(const char *s1, const char *s2, size_t n); 比較字符串s1和s2前n個字符

 

如果兩個字符一樣大,返回值為 0
如果s1>s2,則返回正值,
如果s1<s2,則返回負值.

 

-------------------------------------------------------
int main(int argc, char **argv) { const char *s1="hello"; const char *s2="hello"; const char *s3="aello"; int ret1,ret2; ret1=strncmp(s1,s2,strlen(s1)); ret2=strncmp(s1,s3,strlen(s1)); printf("%d\n",ret1);    //0
    printf("%d\n",ret2);    //7
   return 0; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM