函数strtok和strchr的使用

#include <string.h>
#include <stdio.h>
int main(void) {
	char input[16] = "abc,d";
	char *p;
	p = strtok(input, ",");
	if (p)
		printf("%s\n", p);
	p = strtok(NULL, ",");
	if (p)
		printf("%s\n", p);
	return 0;
}

#include<string.h>
#include<stdio.h>

int main() {
	char string[17];
	char *ptr, c = 'r';
	strcpy(string, "This is a string");
	ptr = strchr(string, c);
	if (ptr) {
		printf("The charactor %c is at position:%d\n", c, ptr - string);
	} else
		printf("The charactor was not found");
	return 0;
}

posted on 2012-06-20 23:41  java课程设计  阅读(444)  评论(0编辑  收藏  举报

导航