Posted on 2011-05-18 15:38
xsong 阅读(259)
评论(0) 编辑 收藏 所属分类:
c
/*
============================================================================
Name : test.c
Author : xsong
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main(void) {
char buffer[] = "buffer example";
// memset 填充字符串
printf("buffer size %i \n", sizeof(buffer));
printf("before memsetd -> %s \n", buffer);
int mpoint = memset(buffer, '*', sizeof(buffer));
printf("memset return point -> %i \n", mpoint);
printf("after memsetd -> %s \n", buffer);
//strlen 取得字符串长度
int buffer_length = strlen(buffer);
printf("buffer size -> %i \n", buffer_length);
//字符串连接
char d[10] = "foo";
char s[10] = "bar";
strcat(d, s);
printf("%s %s\n", d, s);
//字符串分割
char str[] = "root:x::0:root:/root:/bin/bash:";
char *token;
token = strtok(str, ":");
do {
printf("%s \n", token);
} while ((token = strtok(NULL, ":")) != NULL);
return EXIT_SUCCESS;
}