C语言中对字符串进行操作的标准库函数有哪些
C\u8bed\u8a00\u4e2d\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u64cd\u4f5c\u7684\u6807\u51c6\u5e93\u51fd\u6570\u6709\u54ea\u4e9b1\uff09\u5b57\u7b26\u4e32\u64cd\u4f5c
strcpy(p, p1) \u590d\u5236\u5b57\u7b26\u4e32
strncpy(p, p1, n) \u590d\u5236\u6307\u5b9a\u957f\u5ea6\u5b57\u7b26\u4e32
strcat(p, p1) \u9644\u52a0\u5b57\u7b26\u4e32
strncat(p, p1, n) \u9644\u52a0\u6307\u5b9a\u957f\u5ea6\u5b57\u7b26\u4e32
strlen(p) \u53d6\u5b57\u7b26\u4e32\u957f\u5ea6
strcmp(p, p1) \u6bd4\u8f83\u5b57\u7b26\u4e32
strcasecmp\u5ffd\u7565\u5927\u5c0f\u5199\u6bd4\u8f83\u5b57\u7b26\u4e32
strncmp(p, p1, n) \u6bd4\u8f83\u6307\u5b9a\u957f\u5ea6\u5b57\u7b26\u4e32
strchr(p, c) \u5728\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u6307\u5b9a\u5b57\u7b26
strrchr(p, c) \u5728\u5b57\u7b26\u4e32\u4e2d\u53cd\u5411\u67e5\u627e
strstr(p, p1) \u67e5\u627e\u5b57\u7b26\u4e32
strpbrk(p, p1) \u4ee5\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5b57\u7b26\u4f5c\u4e3a\u96c6\u5408\uff0c\u5728\u5f53\u524d\u5b57\u7b26\u4e32\u67e5\u627e\u8be5\u96c6\u5408\u7684\u4efb\u4e00\u5143\u7d20
strspn(p, p1) \u4ee5\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5b57\u7b26\u4f5c\u4e3a\u96c6\u5408\uff0c\u5728\u5f53\u524d\u5b57\u7b26\u4e32\u67e5\u627e\u4e0d\u5c5e\u4e8e\u8be5\u96c6\u5408\u7684\u4efb\u4e00\u5143\u7d20\u7684\u504f\u79fb
strcspn(p, p1) \u4ee5\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5b57\u7b26\u4f5c\u4e3a\u96c6\u5408\uff0c\u5728\u5f53\u524d\u5b57\u7b26\u4e32\u67e5\u627e\u5c5e\u4e8e\u8be5\u96c6\u5408\u7684\u4efb\u4e00\u5143\u7d20\u7684\u504f\u79fb
* \u5177\u6709\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u5728\u5df2\u5904\u7406\u7684\u5b57\u7b26\u4e32\u4e4b\u540e\u586b\u8865\u96f6\u7ed3\u5c3e\u7b26
2\uff09\u5b57\u7b26\u4e32\u5230\u6570\u503c\u7c7b\u578b\u7684\u8f6c\u6362
strtod(p, ppend) \u4ece\u5b57\u7b26\u4e32 p \u4e2d\u8f6c\u6362 double \u7c7b\u578b\u6570\u503c\uff0c\u5e76\u5c06\u540e\u7eed\u7684\u5b57\u7b26\u4e32\u6307\u9488\u5b58\u50a8\u5230 ppend \u6307\u5411\u7684 char* \u7c7b\u578b\u5b58\u50a8\u3002
strtol(p, ppend, base) \u4ece\u5b57\u7b26\u4e32 p \u4e2d\u8f6c\u6362 long \u7c7b\u578b\u6574\u578b\u6570\u503c\uff0cbase \u663e\u5f0f\u8bbe\u7f6e\u8f6c\u6362\u7684\u6574\u578b\u8fdb\u5236\uff0c\u8bbe\u7f6e\u4e3a 0 \u4ee5\u6839\u636e\u7279\u5b9a\u683c\u5f0f\u5224\u65ad\u6240\u7528\u8fdb\u5236\uff0c0x, 0X \u524d\u7f00\u4ee5\u89e3\u91ca\u4e3a\u5341\u516d\u8fdb\u5236\u683c\u5f0f\u6574\u578b\uff0c0 \u524d\u7f00\u4ee5\u89e3\u91ca\u4e3a\u516b\u8fdb\u5236\u683c\u5f0f\u6574\u578b
atoi(p) \u5b57\u7b26\u4e32\u8f6c\u6362\u5230 int \u6574\u578b
atof(p) \u5b57\u7b26\u4e32\u8f6c\u6362\u5230 double \u7b26\u70b9\u6570
atol(p) \u5b57\u7b26\u4e32\u8f6c\u6362\u5230 long \u6574\u578b
3\uff09\u5b57\u7b26\u68c0\u67e5
isalpha() \u68c0\u67e5\u662f\u5426\u4e3a\u5b57\u6bcd\u5b57\u7b26
isupper() \u68c0\u67e5\u662f\u5426\u4e3a\u5927\u5199\u5b57\u6bcd\u5b57\u7b26
islower() \u68c0\u67e5\u662f\u5426\u4e3a\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26
isdigit() \u68c0\u67e5\u662f\u5426\u4e3a\u6570\u5b57
isxdigit() \u68c0\u67e5\u662f\u5426\u4e3a\u5341\u516d\u8fdb\u5236\u6570\u5b57\u8868\u793a\u7684\u6709\u6548\u5b57\u7b26
isspace() \u68c0\u67e5\u662f\u5426\u4e3a\u7a7a\u683c\u7c7b\u578b\u5b57\u7b26
iscntrl() \u68c0\u67e5\u662f\u5426\u4e3a\u63a7\u5236\u5b57\u7b26
ispunct() \u68c0\u67e5\u662f\u5426\u4e3a\u6807\u70b9\u7b26\u53f7
isalnum() \u68c0\u67e5\u662f\u5426\u4e3a\u5b57\u6bcd\u548c\u6570\u5b57
isprint() \u68c0\u67e5\u662f\u5426\u662f\u53ef\u6253\u5370\u5b57\u7b26
isgraph() \u68c0\u67e5\u662f\u5426\u662f\u56fe\u5f62\u5b57\u7b26\uff0c\u7b49\u6548\u4e8e isalnum() | ispunct()
\u51fd\u6570\u540d: strrchr
\u529f \u80fd: \u5728\u4e32\u4e2d\u67e5\u627e\u6307\u5b9a\u5b57\u7b26\u7684\u6700\u540e\u4e00\u4e2a\u51fa\u73b0
\u7528 \u6cd5: char *strrchr(char *str, char c);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
char fullname="./lib/lib1.so";
char *ptr;
ptr = strrchr(fullname,'/');
printf("filename is %s",++ptr);
//\u8fd0\u884c\u7ed3\u679c\uff1afilename is lib1.so
\u51fd\u6570\u540d: strchr
\u529f \u80fd: \u5728\u4e32\u4e2d\u67e5\u627e\u6307\u5b9a\u5b57\u7b26\u7684\u7b2c\u4e00\u4e2a\u51fa\u73b0
\u7528 \u6cd5: char *strchr(char *str, char c);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
char fullname="./lib/lib1.so";
char *ptr;
ptr = strrchr(fullname,'.');
printf("after strchr() is %s",++ptr);
//\u8fd0\u884c\u7ed3\u679c\uff1aafter strchr() is /lib/lib1.so
\u51fd\u6570\u540d: strtok
\u529f \u80fd: \u5728\u4e32\u4e2d\u67e5\u627e\u6307\u5b9a\u5b57\u7b26\u7684\u7b2c\u4e00\u4e2a\u51fa\u73b0
\u7528 \u6cd5: char *strtok(char *s, char *delim);
\u8bf4\u660e\uff1a
1.strtok\u51fd\u6570\u7684\u5b9e\u8d28\u4e0a\u7684\u5904\u7406\u662f\uff0cstrtok\u5728s\u4e2d\u67e5\u627e\u5305\u542b\u5728delim\u4e2d\u7684\u5b57\u7b26\u5e76\u7528NULL(\u2019/0\u2032)\u6765\u66ff\u6362,\u76f4\u5230\u627e\u904d\u6574\u4e2a\u5b57\u7b26\u4e32\u3002\u8fd9\u53e5\u8bdd\u6709\u4e24\u5c42\u542b\u4e49\uff1a\uff081\uff09\u6bcf\u6b21\u8c03\u7528strtok\u51fd\u6570\u53ea\u80fd\u83b7\u5f97\u4e00\u4e2a\u5206\u5272\u5355\u4f4d\u3002\uff082\uff09\u8981\u83b7\u5f97\u6240\u6709\u7684\u5206\u5272\u5355\u5143\u5fc5\u987b\u53cd\u590d\u8c03\u7528strtok\u51fd\u6570\u3002
2.strtok\u51fd\u6570\u4ee5\u540e\u7684\u8c03\u7528\u65f6\u7684\u9700\u7528NULL\u6765\u66ff\u6362s.
3.\u5f62\u53c2s(\u8981\u5206\u5272\u7684\u5b57\u7b26\u4e32)\u5bf9\u5e94\u7684\u53d8\u91cf\u5e94\u7528char s[]=\u201d\u2026.\u201d\u5f62\u5f0f\uff0c\u800c\u4e0d\u80fd\u7528char *s=\u201d\u2026.\u201d\u5f62\u5f0f\u3002
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
void main()
{
char buf[]=\u201dGolden Global View\u201d;
char* token = strtok( buf, \u201d \u201c);
while( token != NULL )
{
printf( \u201d%s \u201c, token );
token = strtok( NULL, \u201d \u201c);
}
return 0;
}
/*\u5176\u7ed3\u679c\u4e3a\uff1a
Golden
Global
View
*/
\u51fd\u6570\u540d\uff1astrncpy
\u529f\u80fd\uff1a\u628asrc\u6240\u6307\u7531NULL\u7ed3\u675f\u7684\u5b57\u7b26\u4e32\u7684\u524dn\u4e2a\u5b57\u8282\u590d\u5236\u5230dest\u6240\u6307\u7684\u6570\u7ec4\u4e2d
\u7528\u6cd5\uff1achar *strncpy(char *dest, char *src, int n);
\u8bf4\u660e\uff1a
\u5982\u679csrc\u7684\u524dn\u4e2a\u5b57\u8282\u4e0d\u542bNULL\u5b57\u7b26\uff0c\u5219\u7ed3\u679c\u4e0d\u4f1a\u4ee5NULL\u5b57\u7b26\u7ed3\u675f\u3002
\u5982\u679csrc\u7684\u957f\u5ea6\u5c0f\u4e8en\u4e2a\u5b57\u8282\uff0c\u5219\u4ee5NULL\u586b\u5145dest\u76f4\u5230\u590d\u5236\u5b8cn\u4e2a\u5b57\u8282\u3002
src\u548cdest\u6240\u6307\u5185\u5b58\u533a\u57df\u4e0d\u53ef\u4ee5\u91cd\u53e0\u4e14dest\u5fc5\u987b\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u6765\u5bb9\u7eb3src\u7684\u5b57\u7b26\u4e32\u3002
\u8fd4\u56de\u6307\u5411dest\u7684\u6307\u9488\u3002
\u4e3e\u4f8b\uff1a
[c-sharp] view plain copy
#include
#include
main()
{
char buf[4];
char *s="abcdefg";
strncpy(buf,s,4);
printf("%s/n",buf);
return 0;
}
/*\u8fd0\u884c\u7ed3\u679c\uff1a
abcd
*/
\u51fd\u6570\u540d: stpcpy
\u529f \u80fd: \u62f7\u8d1d\u4e00\u4e2a\u5b57\u7b26\u4e32\u5230\u53e6\u4e00\u4e2a
\u7528 \u6cd5: char *stpcpy(char *destin, char *source);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s/n", string);
return 0;
}
/*\u8fd0\u884c\u7ed3\u679c
abcdefghi
*/
\u51fd\u6570\u540d: strcat
\u529f \u80fd: \u5b57\u7b26\u4e32\u62fc\u63a5\u51fd\u6570
\u7528 \u6cd5: char *strcat(char *destin, char *source);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s/n", destination);
return 0;
}
/*\u8fd0\u884c\u7ed3\u679c\uff1a
Borland C++
*/
\u51fd\u6570\u540d: strcmp
\u529f \u80fd: \u4e32\u6bd4\u8f83
\u7528 \u6cd5: int strcmp(char *str1, char *str2);
\u770bAsic\u7801\uff0cstr1>str2\uff0c\u8fd4\u56de\u503c > 0\uff1b\u4e24\u4e32\u76f8\u7b49\uff0c\u8fd4\u56de0
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb"\uff1b
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else if(ptr < 0)
printf("buffer 2 is less than buffer 1/n");
else
printf("buffer 2 is equal with buffer 1/n");
return 0;
}
/*\u8fd0\u884c\u7ed3\u679c\uff1a
buffer 2 is greater than buffer 1
*/
\u51fd\u6570\u540d: strncmpi
\u529f \u80fd: \u5c06\u4e00\u4e2a\u4e32\u4e2d\u7684\u4e00\u90e8\u5206\u4e0e\u53e6\u4e00\u4e2a\u4e32\u6bd4\u8f83, \u4e0d\u7ba1\u5927\u5c0f\u5199
\u7528 \u6cd5: int strncmpi(char *str1, char *str2, unsigned maxlen);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
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;
}
\u51fd\u6570\u540d: strcspn
\u529f \u80fd: \u5728\u4e32\u4e2d\u67e5\u627e\u7b2c\u4e00\u4e2a\u7ed9\u5b9a\u5b57\u7b26\u96c6\u5185\u5bb9\u7684\u6bb5
\u7528 \u6cd5: int strcspn(char *str1, char *str2);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
#include
int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;
length = strcspn(string1, string2);
printf("Character where strings intersect is at position %d/n", length);
return 0;
}
\u51fd\u6570\u540d: strdup
\u529f \u80fd: \u5c06\u4e32\u62f7\u8d1d\u5230\u65b0\u5efa\u7684\u4f4d\u7f6e\u5904
\u7528 \u6cd5: char *strdup(char *str);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
#include
int main(void)
{
char *dup_str, *string = "abcde";
dup_str = strdup(string);
printf("%s/n", dup_str);
free(dup_str);
return 0;
}
\u51fd\u6570\u540d: stricmp
\u529f \u80fd: \u4ee5\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u65b9\u5f0f\u6bd4\u8f83\u4e24\u4e2a\u4e32
\u7528 \u6cd5: int stricmp(char *str1, char *str2);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = stricmp(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;
}
\u51fd\u6570\u540d: strerror
\u529f \u80fd: \u8fd4\u56de\u6307\u5411\u9519\u8bef\u4fe1\u606f\u5b57\u7b26\u4e32\u7684\u6307\u9488
\u7528 \u6cd5: char *strerror(int errnum);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s/n", buffer);
return 0;
}
\u51fd\u6570\u540d: strncmp
\u529f \u80fd: \u4e32\u6bd4\u8f83
\u7528 \u6cd5: int strncmp(char *str1, char *str2, int maxlen);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return(0);
}
\u51fd\u6570\u540d: strncmpi
\u529f \u80fd: \u628a\u4e32\u4e2d\u7684\u4e00\u90e8\u5206\u4e0e\u53e6\u4e00\u4e32\u4e2d\u7684\u4e00\u90e8\u5206\u6bd4\u8f83, \u4e0d\u7ba1\u5927\u5c0f\u5199
\u7528 \u6cd5: int strncmpi(char *str1, char *str2, int len);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
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;
}
\u51fd\u6570\u540d: strnset
\u529f \u80fd: \u5c06\u4e00\u4e2a\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u8bbe\u4e3a\u6307\u5b9a\u5b57\u7b26
\u7528 \u6cd5: char *strnset(char *str, char ch, unsigned n);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
printf("string before strnset: %s/n", string);
strnset(string, letter, 13);
printf("string after strnset: %s/n", string);
return 0;
}
\u51fd\u6570\u540d: strpbrk
\u529f \u80fd: \u5728\u4e32\u4e2d\u67e5\u627e\u7ed9\u5b9a\u5b57\u7b26\u96c6\u4e2d\u7684\u5b57\u7b26
\u7528 \u6cd5: char *strpbrk(char *str1, char *str2);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr;
ptr = strpbrk(string1, string2);
if (ptr)
printf("strpbrk found first character: %c/n", *ptr);
else
printf("strpbrk didn't find character in set/n");
return 0;
}
\u51fd\u6570\u540d: strrev
\u529f \u80fd: \u4e32\u5012\u8f6c
\u7528 \u6cd5: char *strrev(char *str);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *forward = "string";
printf("Before strrev(): %s/n", forward);
strrev(forward);
printf("After strrev(): %s/n", forward);
return 0;
}
/*\u8fd0\u884c\u7ed3\u679c\uff1a
Before strrev(): string
After strrev(): gnirts
*/
\u51fd\u6570\u540d: strstr
\u529f \u80fd: \u5728\u4e32\u4e2d\u67e5\u627e\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u6b21\u51fa\u73b0
\u7528 \u6cd5: char *strstr(char *str1, char *str2);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s/n", ptr);
return 0;
}
\u51fd\u6570\u540d: strtod
\u529f \u80fd: \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3adouble\u578b\u503c
\u7528 \u6cd5: double strtod(char *str, char **endptr);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char input[80], *endptr;
double value;
printf("Enter a floating point number:");
gets(input);
value = strtod(input, &endptr);
printf("The string is %s the number is %lf/n", input, value);
return 0;
}
\u51fd\u6570\u540d: strtol
\u529f \u80fd: \u5c06\u4e32\u8f6c\u6362\u4e3a\u957f\u6574\u6570
\u7528 \u6cd5: long strtol(char *str, char **endptr, int base);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *string = "87654321", *endptr;
long lnumber;
/* strtol converts string to long integer */
lnumber = strtol(string, &endptr, 10);
printf("string = %s long = %ld/n", string, lnumber);
return 0;
}
\u51fd\u6570\u540d: strupr
\u529f \u80fd: \u5c06\u4e32\u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd
\u7528 \u6cd5: char *strupr(char *str);
\u4e3e\u4f8b\uff1a
[cpp] view plain copy
#include
#include
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;
/* converts string to upper case characters */
ptr = strupr(string);
printf("%s/n", ptr);
return 0;
}
strcpy(p, p1) 复制字符串
strncpy(p, p1, n) 复制指定长度字符串
strcat(p, p1) 附加字符串
strncat(p, p1, n) 附加指定长度字符串
strlen(p) 取字符串长度
strcmp(p, p1) 比较字符串
strcasecmp忽略大小写比较字符串
strncmp(p, p1, n) 比较指定长度字符串
strchr(p, c) 在字符串中查找指定字符
strrchr(p, c) 在字符串中反向查找
strstr(p, p1) 查找字符串
strpbrk(p, p1) 以目标字符串的所有字符作为集合,在当前字符串查找该集合的任一元素
strspn(p, p1) 以目标字符串的所有字符作为集合,在当前字符串查找不属于该集合的任一元素的偏移
strcspn(p, p1) 以目标字符串的所有字符作为集合,在当前字符串查找属于该集合的任一元素的偏移
* 具有指定长度的字符串处理函数在已处理的字符串之后填补零结尾符
2)字符串到数值类型的转换
strtod(p, ppend) 从字符串 p 中转换 double 类型数值,并将后续的字符串指针存储到 ppend 指向的 char* 类型存储。
strtol(p, ppend, base) 从字符串 p 中转换 long 类型整型数值,base 显式设置转换的整型进制,设置为 0 以根据特定格式判断所用进制,0x, 0X 前缀以解释为十六进制格式整型,0 前缀以解释为八进制格式整型
atoi(p) 字符串转换到 int 整型
atof(p) 字符串转换到 double 符点数
atol(p) 字符串转换到 long 整型
3)字符检查
isalpha() 检查是否为字母字符
isupper() 检查是否为大写字母字符
islower() 检查是否为小写字母字符
isdigit() 检查是否为数字
isxdigit() 检查是否为十六进制数字表示的有效字符
isspace() 检查是否为空格类型字符
iscntrl() 检查是否为控制字符
ispunct() 检查是否为标点符号
isalnum() 检查是否为字母和数字
isprint() 检查是否是可打印字符
isgraph() 检查是否是图形字符,等效于 isalnum() | ispunct()
绛旓細strncat(p, p1, n) 闄勫姞鎸囧畾闀垮害瀛楃涓 strlen(p) 鍙栧瓧绗︿覆闀垮害 strcmp(p, p1) 姣旇緝瀛楃涓 strcasecmp蹇界暐澶у皬鍐欐瘮杈冨瓧绗︿覆 strncmp(p, p1, n) 姣旇緝鎸囧畾闀垮害瀛楃涓 strchr(p, c) 鍦ㄥ瓧绗︿覆涓煡鎵炬寚瀹氬瓧绗 strrchr(p, c) 鍦ㄥ瓧绗︿覆涓弽鍚戞煡鎵 strstr(p, p1) 鏌ユ壘瀛楃涓 strpbrk(p, p1) 浠...
绛旓細1. 瀛楃涓插畾涔変笌鍒濆鍖栵細鍦–璇█涓紝鍙互浣跨敤瀛楃鏁扮粍鏉ュ畾涔夊瓧绗︿覆銆備緥濡傦細`char str[10] = "hello";` 杩欒浠g爜瀹氫箟浜嗕竴涓彲浠ュ瓨鍌10涓瓧绗︾殑瀛楃鏁扮粍str锛屽苟灏嗗瓧绗︿覆"hello"鍒濆鍖栧埌杩欎釜鏁扮粍涓傛敞鎰忥紝瀛楃涓叉槸浠'\0'缁撳熬鐨勫瓧绗﹀簭鍒楋紝缂栬瘧鍣ㄤ細鑷姩鍦ㄥ瓧绗︿覆鏈熬娣诲姞'\0'銆2. 瀛楃涓叉搷浣滐細C璇...
绛旓細1銆丆璇█涓瓧绗︽槸浣跨敤char鏉ュ畾涔夌殑锛屼娇鐢ㄥ叧绯昏繍绠楃锛>锛<锛=锛夊嵆鍙瀛楃杩涜姣旇緝銆2銆佸湪缂栬瘧鍣ㄤ腑瀹氫箟a銆乥涓や釜瀛楃鍨嬪彉閲忥紝骞朵负鍏惰祴鍊笺3銆佽繍琛屼唬鐮佸悗锛屾垜浠彲浠ュ緱鍒板鍥炬墍绀虹粨鏋溿1琛ㄧず鏉′欢涓虹湡锛0琛ㄧず鏉′欢涓哄亣銆4銆佸瓧绗︿覆浣跨敤char[]鏉ュ畾涔夛紝鍙互浣跨敤strcmp()鏉ュ垽鏂ぇ灏忥紝涔熷彲浠ヤ娇鐢ㄥ叧绯昏繍绠楃锛>...
绛旓細涓嶅彲浠ョ敤鍏崇郴杩愮畻绗﹀瀛楃鏁扮粍涓殑瀛楃涓茶繘琛屾瘮杈冦傚彲浠ョ敤鍏崇郴杩愮畻绗﹀瀛楃杩涜鎿嶄綔锛屽嵈涓嶈兘瀵瑰瓧绗︿覆杩涜鎿嶄綔銆傚湪C璇█涓湁浠ヤ笅鍏崇郴杩愮畻绗︼細1銆 < 灏忎簬 2銆 <= 灏忎簬鎴栫瓑浜 3銆 > 澶т簬 4銆 >= 澶т簬鎴栫瓑浜 5銆 == 绛変簬 6銆 != 涓嶇瓑浜 鍏崇郴杩愮畻绗﹂兘鏄弻鐩繍绠楃锛屽叾缁撳悎鎬у潎涓哄乏缁撳悎銆傚叧绯...
绛旓細1. string.h绠浠锛歴tring.h鏄疌璇█涓敤浜庡鐞嗗瓧绗︿覆鐨勪竴涓爣鍑嗗簱銆傚湪缂栧啓娑夊強瀛楃涓叉搷浣滅殑绋嬪簭鏃讹紝閫氬父浼氬寘鍚繖涓ご鏂囦欢锛屼互渚夸娇鐢ㄥ叾涓彁渚涚殑鍚勭瀛楃涓插鐞嗗嚱鏁般2. 涓昏鍔熻兘锛歴tring.h鎻愪緵浜嗚澶氭搷浣滃瓧绗︿覆鐨勫嚱鏁帮紝渚嬪锛歴trcpy鐢ㄤ簬澶嶅埗瀛楃涓诧紝strcat鐢ㄤ簬杩炴帴瀛楃涓诧紝strlen鐢ㄤ簬璁$畻瀛楃涓查暱搴︾瓑銆傛澶栵紝...
绛旓細鏈绠鍗曠殑鏂规硶灏辨槸锛歝har c = 'A'+32 void main(){ char c='a'-32;printf("c %c",c);getch();}
绛旓細c璇█鐨勬爣鍑搴撲腑鎻愪緵浜嗚澶氬瓧绗︿覆鎿嶄綔鍑芥暟锛屾瘮濡俿trcpy銆乻trcat銆乻trlen绛夈傝繖浜涘嚱鏁板彲浠ュ府鍔╂垜浠疄鐜瀵瑰瓧绗︿覆鐨鍚勭鎿嶄綔锛屾瘮濡傚鍒躲佽繛鎺ャ佽绠楅暱搴︾瓑銆傚湪c璇█涓锛屽瓧绗︿覆浣跨敤鍙屽紩鍙凤紙""锛夋潵琛ㄧず锛屽鏋滈渶瑕佸鐞嗗瓧绗︾被鍨嬬殑鏁版嵁锛屽彲浠ョ敤鍗曞紩鍙凤紙''锛夋潵琛ㄧず銆傦細c璇█涓璼tr绫诲瀷鐨勫簲鐢ㄥ満鏅湁鍝簺锛焎...
绛旓細char myString[] = "Hello";杩欓噷锛宍myString`鏄竴涓瓧绗︽暟缁勶紝鐢ㄤ簬瀛樺偍瀛楃涓瞏"Hello"`銆傞渶瑕佹敞鎰忕殑鏄紝瀛楃涓茬殑鏈鍚庝竴涓瓧绗﹂氬父鏄┖瀛楃锛屼互鏍囪瘑瀛楃涓茬殑缁撴潫銆4. char鐨勪娇鐢ㄥ満鏅 char绫诲瀷鍦C璇█涓鏈夊箍娉涚殑搴旂敤銆傚畠鍙互鐢ㄤ簬琛ㄧず鐢ㄦ埛杈撳叆鐨勫崟涓瓧绗︺佸鐞嗘枃鏈暟鎹杩涜瀛楃涓鎿嶄綔绛夈傛澶栵紝char...
绛旓細涓鑸涓 s=鈥渁1a2路路路an鈥(n>=0)銆傚畠鏄紪绋嬭瑷涓〃绀烘枃鏈殑鏁版嵁绫诲瀷銆傚瓧绗︿覆璧嬪兼湁涓瀹氳姹傦紝渚嬪C璇█鐨杩愮畻绗︽牴鏈棤娉鎿嶄綔瀛楃涓层傚湪C璇█涓鎶婂瓧绗︿覆褰撲綔鏁扮粍鏉ュ鐞嗭紝鍥犳锛瀵瑰瓧绗︿覆鐨闄愬埗鏂瑰紡鍜屽鏁扮粍鐨勪竴鏍凤紝鐗瑰埆鏄紝瀹冧滑閮戒笉鑳界敤C璇█鐨勮繍绠楃杩涜澶嶅埗鍜屾瘮杈冩搷浣溿
绛旓細鏄殑锛瀛楃涓鈥淭hat鈥濆皬浜庡瓧绗︿覆鈥淭he鈥濄傚洜涓烘槸鍒╃敤ASCII缂栫爜閫愪綅鎸夌収椤哄簭鏉ユ瘮杈冪殑锛氱涓浣嶁淭鈥濈浉鍚岋紝绗簩浣嶁渉鈥濈浉鍚岋紝绗笁浣嶁渁鈥<鈥渆鈥濓紝鎵浠モ淭hat鈥濆皬浜庘淭he鈥濄備互compareTo()鏂规硶涓轰緥锛屼袱涓瓧绗︿覆姣旇緝澶у皬鏂规硶锛1銆佸鏋滃瓧绗︿覆鐩哥瓑杩斿洖鍊间负0锛屼笉绛夎繑鍥炲叾浠栨暟鍊笺傛瘮杈冩柟娉曟槸鍏堟瘮杈冨搴斿瓧绗...