home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19285 < prev    next >
Encoding:
Text File  |  1993-01-06  |  1.1 KB  |  52 lines

  1. Path: sparky!uunet!comp.vuw.ac.nz!canterbury.ac.nz!chchp.ac.nz!chchp.ac.nz!Matt
  2. From: Matt@chchp.ac.nz (Matt Thompson)
  3. Newsgroups: comp.lang.c
  4. Subject: HELP Please Please (malloc on an array)
  5. Date: Wed, 6 Jan 1993 02:43:23 GMT
  6. Organization: Christchurch Polytechnic
  7. Lines: 40
  8. Distribution: World
  9. Message-ID: <Matt.15.726288203@chchp.ac.nz>
  10. NNTP-Posting-Host: 192.203.99.76
  11.  
  12.  
  13. All I need to do is create an array of strings in memory. Not a hard task at 
  14. all. I can do this easily using the following code but I have had problems 
  15. trying to do this dynamically with malloc etc. I haven't used malloc much 
  16. and don't have the time to get it by trial and error.
  17.  
  18. Could someone please help me as I need to get this done very quickly.
  19.  
  20.  
  21. Code using standard char array
  22. ------------------------------
  23. main()
  24. {
  25. char array1[1000][11];
  26. int temp;
  27.  
  28. for(temp=0;temp<999;temp++)
  29.    sprintf(array1[temp],"Test %d",temp);
  30.  
  31. printf("\n\nEnter a number :");
  32. scanf("%d",&temp);
  33. printf("\n%s",array1[temp]);
  34. }
  35.  
  36.  
  37.  
  38. Code using malloc etc
  39. ---------------------
  40.  
  41. (fill in here, Please)
  42.  
  43.  
  44.  
  45.  
  46. Thanx in advance.
  47.  
  48. Matt Thompson
  49. Software Technician
  50. Christchurch Polytechnic
  51. New Zealand
  52.