#include #include // for strlen #include // for malloc and free // This is the same as strcpy which is in string.h void make_copy(char* dest, char *src){ int i; for(i = 0; src[i]; i++) dest[i] = src[i]; dest[i] = 0; } void double_word_ubuf(char *word, char *result_place){ make_copy(result_place, word); make_copy(result_place + strlen(word), word); } char* double_word_sbuf(char *word){ static char return_space[1024]; if(strlen(word) > 511){ printf("This function does not support that length\n"); return 0; } make_copy(return_space, word); make_copy(return_space + strlen(word), word); return return_space; } int main(){ char array_one[40] = "goose"; char array_two[40]; make_copy(array_two, array_one); printf("Array: %s\n", array_two); char *doubled = double_word(array_one); printf("Our copy: %s\n", doubled); printf("Our copy: %s\n", doubled); free(doubled); make_copy(array_two, "elephant moose mouse snail "); doubled = double_word(array_two); printf("Longer string doubled: %s\n", doubled); free(doubled); make_copy(array_one, "elk deer goat "); double_word_ubuf(array_one, array_two); printf("Doubled array: %s\n", array_two); char *dbant = double_word_sbuf("ant "); char *dbspider = double_word_sbuf("spider "); printf("dbant = %p\n", dbant); printf("dbspider = %p\n", dbspider); printf("dbant = %s\n", dbant); printf("cat types: %s\n", double_word_sbuf("tiger lion cougar bobcat ")); printf("dbant = %s\n", dbant); return 0; } #include #include // Prototype for the custom function called in the assembly void make_copy(char *dest, const char *src); char* double_word(char* word){ char *return_space = malloc(strlen(word) * 2 + 1); make_copy(return_space, word); make_copy(return_space + strlen(word), word); return return_space; }