i am trying to write a split function ...which will accept a array and split it down to diffrent strings on the basis of '-' symbol
can u tell me where i am wrong
i am getting segmentation fault ...i think it is due to the pointer array i used ..
here is code
#include<stdlib.h>
#include<stdio.h>
int split(char spt[])
{
char *t;
int count,i;
t=&spt[0];
count=0;
while(*t!='\0')
{
if(*t=='-')
{
count=count+1;
}
t++;
}
char *ptr[count+1];
count=0;
t=&spt[0];
i=0;
while(*t!='\0')
{
while(*t!='-')
{
ptr[count][i]=*t;
i++;
}
if(*t=='-')
{
count=count+1;
i=0;
}
t++;
}
printf("the first value is %s \n ",ptr[0]);
printf("the second value is %s \n",ptr[1]);
return 0;S
}
int main(int argc ,char *argv[])
{
char check[]="HEllo-le-t-me-confirm-it";
split(check);
return 0;
}