/*
    ptrArith_2.c
    uses pointer arithmetic to copy a string from
    name to word. Uses 2 pointers to traverse the src and dest strings
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define WORD_LENGTH 30

int main(int argc, char *argv[])
{
    char word[WORD_LENGTH];
    char *name = (char *)malloc(WORD_LENGTH * sizeof(char));
    char *word_ptr = word, *name_ptr = name;  /* the start of each string */

    strcpy(name, "Professor");

    /* Copy "Professor" into word with a loop */
    for ( ; *name_ptr != '\0'; word_ptr++, name_ptr++)
        *word_ptr = *name_ptr;
    *word_ptr = '\0'; /* append null character */

    printf("My name is: %s\n", word);

    return 0;
}