C語言字串操作函式

2021-12-30 01:25:42 字數 1924 閱讀 8434

c語言字串操作函式

1. 寫乙個函式實現字串反轉

版本1 - while版

void strrev(char *s)

}版本2 - for版

void strrev(char *s)

}版本3 - 不使用第三方變數

void strrev(char *s)

} 版本4 - 重構版本3

void strrev(char *s)

}版本5 - 重構版本4

void strrev(char *s)

版本6 - 遞迴版

void strrev(const char *s)

2. 實現庫函式strcpy的功能

strcpy函式位於標頭檔案中

版本1strcpy(char * dest, const char * src)

版本2char * __cdecl strcpy(char * dst, const char * src)

版本3strcpy(char * dest, const char * src)

3. 實現庫函式atoi的功能

atoi函式位於標頭檔案中

版本1 - 附說明

int power(int base, int exp)

int __cdecl atoi(const char *s)

return n;

}版本2

int __cdecl atoi(const char *s)

return n;

}4. 實現庫函式strlen的功能

strlen函式位於標頭檔案中

版本1 - while版

size_t  __cdecl strlen(const char * s)

return i;

}版本2 - for版

size_t  __cdecl strlen(const char * s)

版本3 - 無變數版

size_t  __cdecl strlen(const char * s)

版本4 - 重構版本3

size_t  __cdecl strlen(const char * s)

5. 實現庫函式strcat的功能

strcat函式位於標頭檔案中

版本1 - while版

char * __cdecl strcat(char * dst, const char * src)

6. 實現庫函式strcmp的功能

strcmp函式位於標頭檔案中

版本1 - 錯誤的strcmp

int strcmp(const char * a, const char * b)

版本2int __cdecl strcmp (const char * src, const char * dst)

7. 計算字串中母音字元的個數

#include

int is_vowel(char a)

}int count_vowel(const char *s)

return num;

}int main()

8. 判斷乙個字串是否回文:包含乙個單詞,或不含空格、標點的短語。如:madam i'm adam是回文

版本1/*

* 程式功能:判斷乙個單詞,或不含空格、標點符號的短語是否為回文(palindrome)

*/#include

#include

int is_palindrome(const char *s)

else

/* 在s<=end的條件下,只要出現不相等就判斷s不是回文 */

}if(s>end)

is_palindrome=1;

else

is_palindrome=0;

return (is_palindrome);

int main()

C語言字串操作函式

引用自 1.字串反轉 strrev 2.字串複製 strcpy 3.字串轉化為整數 atoi 4.字串求長 strlen 5.字串連線 strcat 6.字串比較 strcmp 7.計算字串中的母音字元個數 8.判斷乙個字串是否是回文 1.寫乙個函式實現字串反轉 版本1 while版 void st...

C語言字串操作函式

c語言字串操作函式 1.字串反轉 strrev 2.字串複製 strcpy 3.字串轉化為整數 atoi 4.字串求長 strlen 5.字串連線 strcat 6.字串比較 strcmp 7.計算字串中的母音字元個數 8.判斷乙個字串是否是回文 1.寫乙個函式實現字串反轉 版本1 while版 v...

C語言字串操作函式

1.函式名 stpcpy 功 能 拷貝乙個字串到另乙個 用 法 char stpcpy char destin,char source 程式例 include include int main void 2.函式名 strcat 功 能 字串拼接函式 用 法 char strcat char des...