2008-05-08 16:42:21 | 9,891 次浏览
———————————————————————————-
分割字符串
———————————————————————————-
#include <string.h>
#include <stdio.h>
char data[] = “A string\tof ,,tokens\nand some more tokens”;
char seps[] = ” ,\t\n”; // 分隔符字符集
char *token;
void main( void )
{
printf( “%s\n\nTokens:\n”, data );
/* Establish string and get the first token: */
token = strtok( data, seps );
while( token != NULL )
{
/* While there are tokens in “string” */
printf( ” %s\n”, token );
/* Get next token: */
token = strtok( NULL, seps );
}
}
———————————————————————————-
字符串转换成数字
———————————————————————————-
char* token = “20″;
int nHour;
nHour = atoi( token);
———————————————————————————-
数字转换成字符串
———————————————————————————-
_itoa( nHour,buf, 10); // 10 代表十进制
char* token = “20″;
char* buf;
int r;
int nHour;
string sHour;
nHour = atoi( token);
nHour += 8;
_itoa( nHour,buf, 10);
sHour = buf;
[ 标签:
字符串 ]
[ 固定链接:
http://m.tanggaowei.com/2008/05/08/75.html ]
没有评论
| 分类 » 手机开发 |