C语言 对字符串进行分割

来源:互联网 发布:java api 1.6 中文 编辑:程序博客网 时间:2024/06/06 10:57
#include <stdlib.h>#include <stdio.h>void splitString(char ** arr,char * source,int & count){count = 0;char *s =NULL;   s=strtok(source," ");  printf("s= %s\n",s);  while(s != NULL)  {   *arr++ = s;   count ++;   s = strtok(NULL," ");  }}void main(){char * arra[30];char str[100] = "i love you";int count = 0;splitString(arra,str,count);for(int i =0;i<count;i++)printf("%s\n",arra[i]);printf("\n");}

0 0
原创粉丝点击