C三级指针复习

#include"stdio.h"
#include"string.h"
#include"stdlib.h"
int saveslip(char *str ,char ***st, char c ,int *len )
{
	char *p ,*q;
	p = str;
	q = str;
	int i = 0; 
	int count;
	*st = (char**)malloc(5*sizeof(char*));
	do
	{
		p = strchr(p,c);
		if(p == NULL)
		{
			break;
		}
		count = p-q;
		(*st)[i] = (char*)malloc(count*sizeof(char)+1);
		memcpy((*st)[i],q,count);
		(*st)[i][count] = '\0';	
		p++;
		q = p;
		//printf("%s\n",(*st)[i]);
	
		i++;	
		
	}while(*p != '\0');
	 *len = i;
}
int main()
{
	char **p = NULL;
	int len = 0;

	saveslip("AB,DEE,FF,",&p,',',&len);
	
		for (int i = 0;i < 3 ;i ++)
		{
			printf("%s\n",(p)[i]);
		}
		
	return 0;
}


你可能感兴趣的:(C语言)