1、strcpy(str2,""); /*將str2清空*/
2、num1=atof(str2); /*將第二個操作數轉換為浮點數*/
3、int strcmp(char *s1,char * s2);
用法:#include <string.h>
功能:比較字符串s1和s2。
說明:
當s1<s2時,返回值<0
當s1=s2時,返回值=0
當s1>s2時,返回值>0
posted @ 2009-06-03 11:35 斷點 閱讀(31) | 評論 (0)
4、strncmp(char *s1,char * s2,int n);
用法:#include <string.h>
功能:比較字符串s1和s2的前n個字符。
說明:
當s1<s2時,返回值<0
當s1=s2時,返回值=0
當s1>s2時,返回值>0
實戰:
在工作中碰見了strncmp函數,在由C轉Java時由于不了解它的返回值范圍,導致出錯,出單員不能錄單,問題比較嚴重。下面是工作中碰見的一段代碼:
if (strcmp(sCtctCde,"014012")==0){
if ((strcmp(sBsnsTyp,"19001")==0) || (strcmp(sBsnsTyp,"19007")==0)){
sprintf(stmp,"該部門屬性為專屬4S店,業務來源只能選擇機構代理!");
return(SetUserError(lpInBuffer,2,stmp));
}else if (strncmp(sProdNo,"03",2)){ //如果相等返回為 0 ,而不是true。
sprintf(stmp,"該部門屬性為專屬4S店,只能出車險業務!");
return(SetUserError(lpInBuffer,2,stmp));
}
}
可參考:http://www.ggv.com.cn/forum/clib/string/strncmp.html
posted @ 2009-09-11 19:28 斷點 閱讀(153) | 評論 (0)