home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!crdgw1!rpi!zaphod.mps.ohio-state.edu!darwin.sura.net!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Newsgroups: comp.lang.c
- Subject: Re: Need help with string arrays
- Message-ID: <1992Dec30.165648@rbg.informatik.th-darmstadt.de>
- Date: 30 Dec 92 15:56:48 GMT
- References: <1992Dec27.232512.22474@news.ysu.edu>
- Sender: news@news.th-darmstadt.de (The News System)
- Organization: TH Darmstadt
- Lines: 24
- Nntp-Posting-Host: rbhp61.rbg.informatik.th-darmstadt.de
-
- In article <1992Dec27.232512.22474@news.ysu.edu>, ah017@yfn.ysu.edu (John B. Lee) writes:
- >
- > In a current program that I am writing I have an array declaration
- > that looks like this:
- >
- > char names[][4];
-
- This would be an array of strings, all 4 chars long.
-
- > How would I use the gets() function to put a string into this array.
- > Am I declaring the array correctly to receive five strings? << This
- > is what I'm trying to do.
-
- You could declare names as char *names[5], but then you had to provide
- storage for the strings yourselve (e.g. via malloc). An alternative would be :
- #define LEN 32
- char names[5][LEN];
- .....
- fgets(name[i],LEN,stdin) /* ensuring that no more than LEN bytes are read */
- ......
-
- --
- Walter Misar It is impossible to enjoy idling thoroughly
- misar@rbg.informatik.th-darmstadt.de unless one has plenty of work to do.
-