home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 19028 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  1.4 KB

  1. 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
  2. From: misar@rbg.informatik.th-darmstadt.de (walter misar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Need help with string arrays
  5. Message-ID: <1992Dec30.165648@rbg.informatik.th-darmstadt.de>
  6. Date: 30 Dec 92 15:56:48 GMT
  7. References: <1992Dec27.232512.22474@news.ysu.edu>
  8. Sender: news@news.th-darmstadt.de (The News System)
  9. Organization: TH Darmstadt
  10. Lines: 24
  11. Nntp-Posting-Host: rbhp61.rbg.informatik.th-darmstadt.de
  12.  
  13. In article <1992Dec27.232512.22474@news.ysu.edu>, ah017@yfn.ysu.edu (John B. Lee) writes:
  14. > In a current program that I am writing I have an array declaration
  15. > that looks like this:
  16. > char names[][4];
  17.  
  18. This would be an array of strings, all 4 chars long.
  19.  
  20. > How would I use the gets() function to put a string into this array.
  21. > Am I declaring the array correctly to receive five strings?  << This
  22. > is what I'm trying to do.
  23.  
  24. You could declare names as char *names[5], but then you had to provide
  25. storage for the strings yourselve (e.g. via malloc). An alternative would be :
  26. #define LEN 32
  27. char names[5][LEN];
  28. .....
  29. fgets(name[i],LEN,stdin)  /* ensuring that no more than LEN bytes are read */
  30. ......
  31.  
  32. -- 
  33. Walter Misar                        It is impossible to enjoy idling thoroughly
  34. misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
  35.