// this example illustrates a way to make the copy of a string #include #include int string_length(char * my_string) { int counter = 0; while(1) { if (my_string[counter] != 0) { counter++; } else { break; } } return counter; } char * copy_string(char * text) { int length = string_length(text); char * temp = (char *) malloc(sizeof(char) * length); int i; // note that we have to put i <= length, not i < length, // so that the NULL character at the end also gets copied. for (i=0; i <= length; i++) { temp[i] = text[i]; } return temp; } int main() { int array_size; int string_length; char * text = "Welcome to CSE 1311"; char * text_copy = copy_string(text); printf("the copy of %s is %s\n", text, text_copy); free(text_copy); }