#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
/*
有一个字符串符合以下特征(”abcdef,acccd,eeee,aaaa,e3eeeee,sssss,";),要求写一个函数(接口),输出以下结果
1) 以逗号分割字符串,形成二维数组,并把结果传出;
2) 把二维数组行数运算结果也传出。
strchr(“aa,aa”,’,’ );
请自己定义一个接口(函数)。
要求1:能正确表达功能的要求,定义出接口(函数)(30分);
要求2:正确实现接口(函数),并实现功能(40分);
要求3:编写正确的测试用例。(30分)。
*/
void sqlit(char*buf,char buf1[10][30],const char c)
{
char *p=NULL,*tmp=NULL;
p=buf;
tmp=buf;
int tmpcount=0;
int count=0;

while(*p!='\0')
{
p=strchr(p,c);
if(p!=NULL)
{
tmpcount=p-tmp;
memcpy(buf1[count],tmp,tmpcount);
buf1[count][tmpcount]='\0';
p=p++;
tmp=p;
count++;
}


}


}

void main()
{
char *p="abcdef,acccd,eeee,aaaa,e3eeeee,sssss,";
char c=',';
char buf1[10][30]={};
sqlit(p, buf1, c);
for(int i=0;i<10;i++){
printf("%s\n",buf1[i]);
}

 

 


system("pause");
}

posted on 2018-08-20 23:16  幽love梦费重寻  阅读(151)  评论(0编辑  收藏  举报