函数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; }