jonathanjeffrey
asked on
int main(int argc, char* argv[]) Stuff
What I want to do is take an integer as input. How do I declare main?
Would I say:
int main(int argc, int* argv[])???
If so, how then do I copy the argument I passed into a new variable?
Thanks.
Would I say:
int main(int argc, int* argv[])???
If so, how then do I copy the argument I passed into a new variable?
Thanks.
int new;
if( argc > 1 ){
new= atoi(argv[1]);
}
if( argc > 1 ){
new= atoi(argv[1]);
}
i doubt if you can change the signature of main method as:
int main(int argc, int* argv[])
what you can do is to convert char* into integers. this you can do using atoi method.
check out:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html
Hope it helps.
int main(int argc, int* argv[])
what you can do is to convert char* into integers. this you can do using atoi method.
check out:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html
Hope it helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something like...
int n = atoi(argv[1]);
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html