文字列から 2 つの部分文字列を抽出しようとしています。しかし、それはセグメンテーション違反を示しています。
コードは次のとおりです。
const char *str;
char *s1, *s2;
str = "name:d";
char *pos = strchr(str, ':');
size_t no = 1,
index = pos - str;
if (index > 0)
{
strncpy(s1, str, index);
cout << "name is:" << s1;
index++;
strncpy(s2, str + index, no);
cout << "direction is:" << s2;
}