home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!agate!darkstar.UCSC.EDU!cats.ucsc.edu!banshee
- From: banshee@cats.ucsc.edu (Wailer at the Gates of Dawn)
- Newsgroups: comp.lang.c
- Subject: Re: HELP Please Please (malloc on an array)
- Date: 6 Jan 1993 21:09:41 GMT
- Organization: University of California, Santa Cruz
- Lines: 41
- Distribution: World
- Message-ID: <1ifhqlINNjap@darkstar.UCSC.EDU>
- References: <Matt.15.726288203@chchp.ac.nz>
- NNTP-Posting-Host: am.ucsc.edu
-
-
- Matt@chchp.ac.nz (Matt Thompson) writes:
-
-
- >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
- >---------------------
- main()
- {
- char *array1[1000];
- int i;
-
- for (i = 0; i < 999; i++) {
- array1[i] = malloc(11);
- sprintf(array1[i], "Test %d", i);
- }
-
- printf("\n\nEnter a number: ");
- scanf(" %d", &i);
- printf("\n%s\n", array1[i]);
- }
-
- --
- The Wailer at the Gates of Dawn | banshee@cats.UCSC.EDU |
- Just who ARE you calling a FROOFROO Head? | |
- DoD#0667 "Just a friend of the beast." | banshee@ucscb.UCSC.EDU |
- 2,3,5,7,13,17,19,31,61,89,107,127,521,607....| banshee@ucscb.BITNET |
-