c - 'Character Array' of integers to 'Integer array' -
my requirement :
taking (unknown number) of integers input user , store them in numeric array.
eg: input: 25 3 4 78. want them stored in numeric array, num as
num[0] = 25 num[1] = 3 num[2] = 4 num[3] = 78 . . . what did :
stored input in character array.
gets(arr); //takes input command prompt , stores in string
then i'm trying find spaces , separate characters, turns out
double digit number(say,25)stored2,5not25.
how achieve this?
well, did not show code, i'll not provide code, i'll more happy provide flow-chart.
- define 1 array large enough (maybe change dynamic allocation later).
- take input user (not command line arguments) using
fgets(). - use
strtok()tokenize input using spacedelimiter. - if non-null token received, use
strtol()convert tokenintorlong. - if
strtok()returned null means you've got tokens , input empty, finish up, gotintarray.
Comments
Post a Comment