多項式の係数を char 配列から int 配列に入れようとして
いますが、これは次のとおりです。
char string[] = "-4x^0 + x^1 + 4x^3 - 3x^4";
スペースで-4x^0
x^1
4x^3
3x^4にトークン化できます
だから私は取得しようとしています: -4, 1, 4, 3 を int 配列に
int *coefficient;
coefficient = new int[counter];
p = strtok(copy, " +");
int a;
while (p)
{
int z = 0;
while (p[z] != 'x')
z++;
char temp[z];
strncpy(temp[z], p, z);
coefficient[a] = atoi(temp);
p = strtok(NULL, " +");
a++;
}
ただし、 strncpy(temp[z], p, z); で char* を char に変換できないというエラーが表示されます。
error: invalid conversion from ‘char’ to ‘char*’
error: initializing argument 1 of ‘char* strncpy(char*, const char*, size_t)’
これを行う最良の方法は何ですか?