I'm trying to put the coefficients of polynomials from a char array into an int array
I have this:
char string[] = "-4x^0 + x^1 + 4x^3 - 3x^4";
and can tokenize it by the space into
-4x^0
x^1
4x^3
3x^4
So I am trying to get: -4, 1, 4, 3 into an int array
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++;
}
However, Im getting an error that I cant convert a char* into a char on strncpy(temp[z], p, z);
error: invalid conversion from ‘char’ to ‘char*’
error: initializing argument 1 of ‘char* strncpy(char*, const char*, size_t)’
What would be the best way to do this?