Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!pilchuck!dataio!gtenmc!csp From: csp@gtenmc.UUCP Newsgroups: comp.lang.c Subject: Re: Novice question about malloc and pointers Message-ID: <1139@gtenmc.UUCP> Date: 26 Apr 91 18:56:05 GMT References: <9104171614.AA14362@enuxha.eas.asu.edu> Reply-To: csp@gtenmc.UUCP () Organization: GTE Telecom, Inc. Bothell, WA Lines: 39 In article <9104171614.AA14362@enuxha.eas.asu.edu> trotter@enuxha.eas.asu.edu (Russell T. Trotter) writes: >constant. My question is how do I allocate the memory for each ^^^^^^^^ Malloc , my dear Russell. Malloc ! >character position? Do all the characters strings for each element >in the array need to be allocated contiguously? The problem involves ^^^^^^^^^^^^ Did't you know that memory is linear ! ( NO ) >reading in lines of input. Each line would be stored as a string and >the number of lines make up the number of elements in the array. >Any information would be greatly appreciated. Thank you. This proves without doubt 'Ignorance is NOT bliss'. Solution : #include #include #include #define MAX 20 #define MAX_SZ 512 char *str[MAX]; Read_Input() { int i; char buff[MAX_SZ]; for ( i = 0 ; i < MAX ; i++ ) str[i] = malloc(strlen(gets(buff)+1)), strcpy(str[i],buff); } C S Palkar -- > >trotter@enuxha.eas.asu.edu