發(fā)布時間:2011-09-16 共2頁
字符串處理函數(shù)
1、將格式化數(shù)據(jù)寫入字符串:sprintf
int sprintf( char *buffer, const char *format, ... );
將數(shù)據(jù)打印到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、字符串長度查詢函數(shù): strlen
int strlen(const char *s);
3、字符串復制函數(shù):strcpy、strncpy
char *strcpy(char *dest, const char *src);
4、字符串連接函數(shù): strcat
char *strcat(char *dest, const char *src);
5、字符串比較函數(shù): strcmp、strncmp、stricmp、strnicmp
字符串比較函數(shù)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''
字符串搜索函數(shù): strcspn、strspn、strstr、strtok、strchr