wincc中字符串的使用

wincc的内部变量中定义2个文本变量16位字符集,通过输入/输出域给定,怎样通过c语言脚本,判断两个字符串是否相等?

最佳答案

函数名: strcmp 
 功  能: 串比较 
 用  法: int strcmp(char *str1, char *str2); 
 看Asic码,str1>str2,返回值 > 0;两串相等,返回0
 程序例: 

 #include <string.h> 
 #include <stdio.h> 

 int main(void) 
  { 
     char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; 
     int ptr; 

     ptr = strcmp(buf2, buf1); 
     if (ptr > 0) 
        printf("buffer 2 is greater than buffer 1\n"); 
     else 
        printf("buffer 2 is less than buffer 1\n"); 

     ptr = strcmp(buf2, buf3); 
     if (ptr > 0) 
        printf("buffer 2 is greater than buffer 3\n"); 
     else 
        printf("buffer 2 is less than buffer 3\n"); 

     return 0; 
  } 
   
   
   

 函数名: strncmpi 
 功  能: 将一个串中的一部分与另一个串比较, 不管大小写 
 用  法: int strncmpi(char *str1, char *str2, unsigned maxlen); 
 程序例: 

 #include <string.h> 
 #include <stdio.h> 

 int main(void) 
 { 
    char *buf1 = "BBB", *buf2 = "bbb"; 
    int ptr; 

    ptr = strcmpi(buf2, buf1); 

    if (ptr > 0) 
       printf("buffer 2 is greater than buffer 1\n"); 

    if (ptr < 0) 
       printf("buffer 2 is less than buffer 1\n"); 

    if (ptr == 0) 
       printf("buffer 2 equals buffer 1\n"); 

    return 0; 
 } 
   
 

提问者对于答案的评价:
十分感谢!

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc274334.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2019年6月11日
下一篇 2019年6月11日

相关推荐