/* CS107 Realloc Example
 * Code by Nick Troccoli
 * 
 * This program prints out a string containing a random number
 * (0 or more) of lowercase letters by building up a string from
 * characters read from getRandomCharacter until that function returns
 * the null terminator.  It simulates reading in live data of an unknown
 * size, making more space for it as we go using realloc.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <time.h>       // for random number generation
#include <stdlib.h>     // for random number generation


/* This function returns a random letter that is
 * either lowercase, or the null terminator.
 */
const char *letters = "abcdefghijklmnopqrstuvwxyz";
char getRandomCharacter() {
    // generate a random index from 0-26, inclusive (including null terminator option)
    int randomIndex = rand() % (strlen(letters) + 1);
    return letters[randomIndex];
}

/* This function reads characters from getRandomCharacter and builds up a string
 * until getRandomCharacter returns the null terminator.
 * The returned string is heap-allocated, and it
 * is the caller's responsibility to free it.
 */
char *readStreamingData() {
    // TODO
    return NULL;
}

int main(int argc, char const *argv[]) {
    // Random number initialization
    srand(time(NULL));

    char *str = readStreamingData();
    printf("%s\n", str);
    free(str);

    return 0;
}
