Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!emcard!wa4mei!kd4nc!npiatl!dkelly From: dkelly@npiatl.UUCP (Dwight Kelly) Newsgroups: comp.lang.c Subject: Re: Probably an easy or dumb question Keywords: scan Message-ID: <420@npiatl.UUCP> Date: 11 Aug 89 14:02:16 GMT References: <1949@leah.Albany.Edu> Reply-To: dkelly@npiatl.UUCP (Dwight Kelly) Organization: Network Publications, Inc. Atlanta, GA Lines: 27 In article <1949@leah.Albany.Edu> rds95@leah.Albany.Edu (Robert Seals) writes: >Hello frenz, is it workable to pass only the base address of an array >to "?scanf" and have it convert into successive memory locations? > >int d[4]; > >scanf("%d %d %d %d", d); > Not possible. Scanf reads the variable addresses off of the stack. In your example, it would get the address of d[0] and then get three random addresses for the next three %d. One solution is: scanf("%d %d %d %d", &d[0], &d[1], &d[2], &d[3]); or: int i; for (i=0; i<4; i++) scanf("%d", &d[i]); -- Dwight Kelly UUCP: gatech!npiatl!dkelly Director R&D AT&T: (404) 962-7220 Network Publications, Inc 2 Pamplin Drive Lawrenceville, GA 30245 Publisher of "The Real Estate Book" nationwide!