i have a string in which words are separated by space

i want to create an array of strings ,each string contains a word
from the original string

i tried like this.
but the debugger doesnt show me the stucture
i just says bad ptr

i cant see why its not breaking into peaces
??
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct node node;
struct node{
	int value;
	struct node * next;
};
 int countletters(char *str);
 char * sortbycount(char* str);
void main()
{
	int g;
	char  str[18]="aabx bXcb bBxaDAa";
	char * r;
	g=countletters(str);
	r=sortbycount(str);
}


int countletters(char *str)
{
	int i,cnt=0;
	int ch[26]={0};
    for (i=0;i<(int)strlen(str);i++)
	{
       if ((str[i]>='a')&&(str[i]<='z'))
	   {
          ch[str[i]-'a']=1;
	   }
	   if ((str[i]>='A')&&(str[i]<='Z'))
	   {
          ch[str[i]-'A']=1;
	   }
	}
	for (i=0;i<26;i++)
	{
		if(ch[i]==1){ cnt++;}
	}
	printf("%d",cnt);
   return cnt;
}

char * sortbycount(char* str)
{
  int start=0,i,cnt=0;char** arr;
  for (i=0;i<(int)strlen(str);i++)
  {
    if (str[i]==' ') cnt++;
  }
  arr=(char**)malloc(sizeof(char*)*cnt);
  i=0;
  do
  {
     for (i=start;str[i]!=' ';i++);
     arr[i]=(char*)malloc(sizeof(char)*(i-start));
     sprintf(arr[i],"%s",str+i); 
	 start=i;

  }while(i<cnt);
  
 return str;
}