代码改变世界

C语言学习

2011-05-31 13:45  Jeff  阅读(467)  评论(0编辑  收藏  举报
 
int main(){
int i;
char * msg= (char *)malloc(6);
char buff[] ="2mxbcd";
char thechar[20];
char otherchar[] ="123456";
msg =buff;
printf("array -1 %d",otherchar[-1]);
//printf("size of unsigned short is %d, char is %d",sizeof(unsigned short), sizeof(char));
printf("msg is %d,%d,%d,%d,%d,%d",msg[0],msg[1],msg[2],msg[3],msg[4],msg[5]);
printf("msg is %d,msg +1 is %d, value: %d",msg,msg+1,*(msg+1));

unsigned short test1 =(*((unsigned short*)(msg+1)));
printf("test1 is %d",test1);
memcpy(msg,msg+1,5);
printf("msg is %c,%c,%c,%c,%c,%c",msg[0],msg[1],msg[2],msg[3],msg[4],msg[5]);

memcpy(thechar,otherchar,6);
printf("thechar is %c,%c,%c,%c,%c,%c,%cn",thechar[0],thechar[1],thechar[2],thechar[3],thechar[4],thechar[5],thechar[6]);
for(i=6;i > 0;i--){
    thechar[i] =thechar[i-1];
}

printf("thechar is %c,%c,%c,%c,%c,%c,%cn",thechar[0],thechar[1],thechar[2],thechar[3],thechar[4],thechar[5],thechar[6]);

for(i=7;i > 0;i--){
    printf("%dn",i);
}
return 0;
}