strcat dumping core in the situation like
main()
{
char* item;
char* p=sat_item;
char type[5];
item=(char*) malloc(strlen(p));
strncpy(type,p,4);
type[4]='\0';
strcat(item,type); //dumping core
}
I couldn't get why strcat dumping core?
strcat dumping core in the situation like
main()
{
char* item;
char* p=sat_item;
char type[5];
item=(char*) malloc(strlen(p));
strncpy(type,p,4);
type[4]='\0';
strcat(item,type); //dumping core
}
I couldn't get why strcat dumping core?
For one I cannot find where sat_item is declared. Could the post the whole code?
char*p = "sat_item"; // where sat_item is token using strtok()
strtok() might be returning NULL. Did you check it?
The code will work if p points to a string like "sat_item".