字符串处理函数
1、将格式化数据写入字符串:sprintf
int sprintf( char *buffer, const char *format, ... );
将数据打印到buffer中
例如:char result[100];
int num = 24;
sprintf( result, "%d", num );
例如:char string[50];
int file_number = 0;
sprintf( string, "file.%d", file_number );
file_number++;
output_file = fopen( string, "w" );
又例如:char result[100];
float fnum = 3.14159;
sprintf( result, "%f", fnum );
2、字符串长度查询函数: strlen
int strlen(const char *s);
3、字符串复制函数:strcpy、strncpy
char *strcpy(char *dest, const char *src);
4、字符串连接函数: strcat
char *strcat(char *dest, const char *src);
5、字符串比较函数: strcmp、strncmp、stricmp、strnicmp
字符串比较函数strcmp(分大小写)
int strcmp(const char *s1, const char *s2);
Return Value
Return value
Explanation
less than 0
str1 is less than str2
equal to 0
str1 is equal to str2
greater than 0
str1 is greater than str2''
字符串搜索函数: strcspn、strspn、strstr、strtok、strchr