TIP: Click on subject to list as thread! ANSI
echo: usr_modems
to: DAPHNELK@THEMALL.NET
from: MIKE MCCLAIN
date: 1998-03-28 21:43:00
subject: array help for a student

-=> 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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.