View Full Version : pass arguments into array
Heretic09
October 31st, 2005, 05:40 PM
Does any one know how to change a passed argument into an array?
If the user types in foo 123456
it would get passed into an array, then the output would split up the individual numbers eg
cout << array[0] would output 1
cout << array[1] would output 2 etc
any ideas?
GoldBuggie
October 31st, 2005, 07:36 PM
just use a char array. Let's say
char str[256];
cin>>str;
cout << str[0] .. etc
remembet that everythihng is char so if you want to use it as numbers convert it using
int x = atoi(str[0]);
You could also use the string class in c++ instead of char*.
#include <string.h>
string str;
...
raublekick
October 31st, 2005, 07:38 PM
out of curiosity, are you writing a basic shell program?
thumper
October 31st, 2005, 08:17 PM
how about just treating it like a std::string?
Heretic09
October 31st, 2005, 08:31 PM
raublekick: nah its actually a keygen i'm working on
Thanks for the quick reply. I'll try that, any ideas for groupings?
Basically i'll be passing the arguments to main via:
int main(int argc, char *argv[])
so if the user puts in: foo 123456
cout << variable[0]; should output 12
cout << variable[1]; should output 34 etc
thanks again.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.