-=> DAPHNELK@THEMALL.NET wrote to ALL <=-
DA> Subject: array help for a student
DA>
DA> I am trying to input an array of type int. I want to enter it all on one
DA> line without haveing to press enter after each number. also is there a
way
DA> to do this when some of the array is
DA> has dashes - inbetween the numbers. If not how do I do this because I
need
DA> to make calculations with the array but I don't think I can if the array
DA> is
DA> of a char type. thanks for any help
scanf() requires that the array always be in a particular format.
all on one line use fgets(), but you've got to separate one number from
the next with some character whether space, comma or whatever.
then use:
strtok()
array[0]=atoi()
while(strtok())
if(dash separated)
do something apropriate, then add to array
else
array[++i]= atoi()
syntax and parameters left to the student.
remember itinially you're dealing with chars.
good luck , MiKe
--- MultiMail/Linux v0.6a
---------------
* Origin: Shakey Jake's *All Free BBS!* Santee, Ca (1:202/1324)
|