發布時間:2011-09-16 共2頁
字符串處理函數
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