home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!comp.vuw.ac.nz!canterbury.ac.nz!chchp.ac.nz!chchp.ac.nz!Matt
- From: Matt@chchp.ac.nz (Matt Thompson)
- Newsgroups: comp.lang.c
- Subject: HELP Please Please (malloc on an array)
- Date: Wed, 6 Jan 1993 02:43:23 GMT
- Organization: Christchurch Polytechnic
- Lines: 40
- Distribution: World
- Message-ID: <Matt.15.726288203@chchp.ac.nz>
- NNTP-Posting-Host: 192.203.99.76
-
-
- All I need to do is create an array of strings in memory. Not a hard task at
- all. I can do this easily using the following code but I have had problems
- trying to do this dynamically with malloc etc. I haven't used malloc much
- and don't have the time to get it by trial and error.
-
- Could someone please help me as I need to get this done very quickly.
-
-
- Code using standard char array
- ------------------------------
- main()
- {
- char array1[1000][11];
- int temp;
-
- for(temp=0;temp<999;temp++)
- sprintf(array1[temp],"Test %d",temp);
-
- printf("\n\nEnter a number :");
- scanf("%d",&temp);
- printf("\n%s",array1[temp]);
- }
-
-
-
- Code using malloc etc
- ---------------------
-
- (fill in here, Please)
-
-
-
-
- Thanx in advance.
-
- Matt Thompson
- Software Technician
- Christchurch Polytechnic
- New Zealand
-