首页 > 其他 > 详细

字符指针

时间:2016-12-28 18:05:13      阅读:130      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>

void strcpy(char *s, char *t)
{
    while((*t++ = *s++) != \0)
        ;
    *t = *s;
}

int main()
{
    char *s = "how are you?";
    char *t;
    
    strcpy(s , t);
    printf("%s\n", s);
    printf("%s\n", t);
    return 0;
}
#include<stdio.h>

void strcpy(char *s, char *t)
{
    int i;
    
    i = 0;
    //s[0] = ‘a‘;  //这句无法正常运行, 下一句可以
    t[0] = z;   
    //while((t[i] = s[i++]) != ‘\0‘)
        ;
}

int main()
{
    char *s = "how are you?";
    char *t;
    
    strcpy(s , t);
    printf("%s\n", s);
    printf("%s\n", t);
    return 0;
}

 

c89:
s所指向的字符串常量是不可以被改变的,

t可以当作字符数组使用。在

void strcpy(char *s, char *t) 的函数体中,可以用字符数组形式访问、修改内容

字符指针

原文:http://www.cnblogs.com/xkxf/p/6229999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!