I'm creating a program that reads from the command line two integer vectors, and transforms them into polinoms, allowing us to sum, multiply, and subtract them. The idea would be to call this in the console
&> ./polinom 2 1 1 3 1 1 1 (polinom is the name of the program.2 indicates the length of the first integer vector. 1 1 are the coefficients of the monoms of the first polinom. 3 indicates the length of the second vector, and 1 1 1 its coefficients)
However, i get a lot of errors with this implementation of main(void), specially on the declaration of a_length, and b_length. I don't know what I'm doing wrong, and would like some guidance in what i should do.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main (int argc, char* argv[])
{
unsigned a_length = unsigned(argv[1]), b_length = unsigned (argv[2+argv[1]]);
int* ap, bp;
ap = newint[a_length];
bp = newint[b_length];
cout << "longitudes : " << a_length << " " << b_length << endl;
for (unsigned i = 0; i< a_length ; i++){
*(ap+i) = argv[i+2];
}
for (unsigned i = 0; i< b_length ; i++){
*(bp+i) = argv[argv[1]+3+i];
}
Polinom a(ap,a_length), b(bp, b_length);
return 0;
}
argv stores the arguments as C strings -character arrays-, to convert them to numbers see http://www.cplusplus.com/articles/numb_to_text/#s2n ( the example uses std::string but it should work also with C strings )
yeah, i was smelling like i was trying to interpret strings as unsigned. But i thought g++ wouldn't emmit error.
I made the conversion, but im still getting error In function `int main(int, char**)': invalid types `char**[char*]' for array subscript here, in the declaration of a_length and b_length:
* works for just one variable on declaration, add another star before bp: int *ap = newint[a_length] , *bp= newint[b_length];
( I like more the int *p; notation than the int* p; one for this reason. )