久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

字符串面試題

 昵稱7335426 2011-07-15

一般面試字符串的題目分四種:1,, 基本運算(求長度,連接,,比較)2. 格式轉(zhuǎn)換(atoi, itoa) 3.字符串翻轉(zhuǎn) 4. 模式匹配,。

1. 基本運算

a. 賦值操作

函數(shù)原型:int StrAssign(const char *s, char *t)

函數(shù)說明:將s的內(nèi)容付給t

函數(shù)定義:

int StrAssign(const char *s, char *t){
 char *p = t;
  while(*s !='\0'){
  *p++ = *s++;
 }
 *p = '\0';

 return 0;
}

b. 連接操作

函數(shù)原型:int Concat(char *s, const char *t)

函數(shù)說明:將串t連接到串s的尾部,形成一個新串

函數(shù)定義:
int Concat(char *s, const char *t){
 //首先找到串s的尾部
 char *p = s;

 while(*p != '\0') p++;//循環(huán)結(jié)束以后的p就是s的尾部

  while(*t !='\0')   *p++ = *t++; 
  *p='\0';//添加尾部字符

  return 0;
}

c.求長度

函數(shù)原型:int StrLen(char *s)

函數(shù)說明:返回串s的長度

函數(shù)定義:

int StrLen(char *s){
 int len = 0;

 while(*s != '\0'){
  len ++;
  s++;
 }

 return len;
}

d. 字符串比較

函數(shù)原型:int StrCmp(const char *s, const char *t)

函數(shù)說明:比較兩個串的大小,,返回值為-1,0,1表示s<t, s=t,s>t,。

函數(shù)定義:

int StrCmp(const char *s, const char *t){
 while((*s != '\0')&&(*t != '\0')){
   if(*s++ - *t++ > 0) return 1;
  else if( *s++ - *t++ <0) return -1;
  else return 0;
 }

 return 0;
}

//不區(qū)分大小寫的字符串比較函數(shù)
int stricmp(const char *s, const char *t){ 
 while((*s != '\0')&&(*t != '\0')){  
  if(toupper(*s++) - toupper(*t++) > 0) return 1;
  else if(toupper(*s++) - toupper(*t++) <0) return -1;
  else return 0;
 }

 return 0;
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,,謹防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報,。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多