#include <stdio.h> /* 復制字符串 */ void cpystr(char * source, char * target) { while(*target++ = *source++); } /* 取得字符串的長度 */ int strlen(char * str) { int size = 0; while(*str++ != '\0') { size++; } return size; } int main(void) { char* s = "Hello, World."; char c[10]; char * p = c; cpystr(s, p); printf("%s\n", p); printf("%d\n", strlen(p)); return 0; }
#include <stdio.h> /* 復制字符串 */ void cpystr(char * source, char * target) { while(*target++ = *source++); } /* 取得字符串的長度 */ int strlen(char * str) { int size = 0; while(*str++ != '\0') { size++; } return size; } int main(void) { char* s = "Hello, World."; char c[strlen(s)]; char * p = c; cpystr(s, p); printf("%s\n", p); printf("%d\n", strlen(p)); return 0; }
strlen(s)];