常見C語言面試題之一 字串代替 字串轉換整數

2021-04-19 21:40:39 字數 1079 閱讀 5985

#include "stdafx.h"

using

namespace std;

//--------字元替代問題

char* translate(char* psrc, const

char cfindchar, const

char* preplacestr, char* ptag)  

else

}  return ptag;  

}  //--------字串轉換為整數

int myatoi(const

char* s)

if(s[i] == '+')

i++;

while(s[i] != '/0')

result = result * flag;

return result;

}//--------整數轉換為字串

void itoa (int n,char s)

while ((n/=10)>0);//刪除該數字

if(sign<0)

s[i++]='-';

s[i]='/0';

for(j=i;j>=0;j--)//生成的數字是逆序的,所以要逆序輸出

printf("%c",s[j]);

printf("/n");

}int _tmain(int argc, _tchar* argv)

;  char   szrep ="(***)";     

char result[256] = ;

translate(szsrc,'o',szrep,sztag);       

for(unsigned int i=0;iprintf("%s/n",sztag);

printf("%s/n",result);

//-----------------------

int i = atoi("    -321" );

printf("%d/n",i);

char ch[256]=;

itoa(-23456, ch);   

return 0;   

}

常見C語言面試題之一 字串代替 字串轉換整數

1.include stdafx.h 2.using namespace std 3.字元替代問題4.char translate char psrc,const char cfindchar,const char preplacestr,char ptag 5.16.else 17.20.21.r...

面試基礎(一) 字串函式

最新更新strncpy strstr函式 1 include2 include3 using namespace std 45 6int my strlen const char str 715 return count 16 1718 19int main 20話說這真的不是很難,要說難一點的還是...

Redis入門之一 字串(string)

redis 中最簡單的資料結構,它既可以儲存文字 比如 hello world 又可以儲存數字 比如整數 10086 和浮點數 3.14 還可以儲存二進位制資料 比如 10010100 redis 為這幾種型別的值分別設定了相應的操作命令,讓使用者可以針對不同的值做不同的處理。為字串鍵設定值 獲取字...