学习language C
2011-05-26 15:29 Jeff 阅读(417) 评论(0) 编辑 收藏 举报
不解释.
int main(){ int i; char * msg = (char *)malloc(6); char buff[] = "2mxbc"; char onechar; for(i=0;i < strlen(buff);i++) printf("the %d char is %c",i,buff[i]); printf("the length of buff is %d",strlen(buff)); memcpy((char *)msg,buff,strlen(buff)); for(i=0;i < = strlen(buff);i++) printf("the %d char is %c",i,msg[i]); for(i=0;i < strlen(buff)-1;i++) msg[i]=msg[i+1]; for(i=0;i < strlen(buff);i++) printf("After copy the %d char is %c",i,msg[i]); strncpy(&onechar,&msg[4],1); printf("the char is %d",onechar); return 0; }