#include <stdio.h> void copy_string(char*, char*); int main(void) { char *a = "I am a teacher."; char *b = "You are a student."; printf("string_a = %s\nstring_b = %s\n", a, b); copy_string(a, b); printf("string_a = %s\nstring_b = %s\n", a, b); return 0; } void copy_string(char *from, char *to) { for (; *from != '\0'; ++from, ++to) { *to = *from; } *to = '\0'; }
gcc下:
codeblocks下: