home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18607 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.4 KB  |  42 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!sunic!dkuug!daimi!u920496
  3. From: u920496@daimi.aau.dk (Hans Erik Martino Hansen)
  4. Subject: array initialisation
  5. Message-ID: <1992Dec18.135255.19302@daimi.aau.dk>
  6. Keywords: c,array,initialize,bla bla
  7. Sender: u920496@daimi.aau.dk (Hans Erik Martino Hansen)
  8. Organization: DAIMI: Computer Science Department, Aarhus University, Denmark
  9. Date: Fri, 18 Dec 92 13:52:55 GMT
  10. Lines: 30
  11.  
  12. Hello outthere in netland!
  13.  
  14. In a program a friend is writing he needs an array of an array of ints.
  15. The number of elements is not fixed.
  16.  
  17. This is how I would write the source:
  18. /* example.c */
  19. int **tank = {
  20.     { 10,24,563,3245,234,52345,234,-1 },
  21.     { 1,645,21,-1 },
  22.     { 243,33,452,122,422,123,-1 }
  23. };
  24. ...
  25.  
  26. I cannot make the compiler accept "example.c". But if I change the definition
  27. of tank to: int tank[][8] = ... it works fine. But I think this solution
  28. is ugly code, and definately not according to the spirit of C. 
  29. Some of the elements could be very long, and some consist only of a few
  30. ints. Then a lot of unused memery is allocated, and even more important:
  31. you'll have to count the elements by hand.
  32.  
  33. My question is simply: is there a way to do, what I intended to in example.c
  34.  
  35. Please mail me directly, as I have no access to newsgroups during the
  36. holiday. Thanks in advance!
  37.  
  38. Erik Martino Hansen  | u920496@daimi.aau.dk
  39. Trige Parkvej 9,ST1  | 
  40. DK-8380  Trige       | "Information wants to be free!"
  41. Denmark              |
  42.