/* File: allocate3.c Strings are really dynamically allocated character arrays. We use NewArray and FreeBlock from the course library. */ #include #include "genlib.h" #include "simpio.h" /* On some systems you should include the following */ #include main() { char *letters, c ; int i ; /* Use NewArray to allocate 27 characters */ letters = NewArray(27,char) ; /* Lets use it as an array */ i = 0 ; c = 'a' ; while (c <= 'z') { letters[i] = c ; c++ ; i++ ; } /* Add the null character at the end */ letters[26] = '\0' ; /* print out the array as a string */ printf("letters: %s\n", letters) ; /* Give up use of the memory block */ FreeBlock(letters) ; } --------------------------------------------------------- letters: abcdefghijklmnopqrstuvwxyz