码迷,mamicode.com
首页 > 其他好文 > 详细

字符指针

时间:2016-12-28 18:06:51      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:字符数组   ret   修改   使用   strcpy   i++   blog   pre   return   

#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) 的函数体中,可以用字符数组形式访问、修改内容

字符指针

标签:字符数组   ret   修改   使用   strcpy   i++   blog   pre   return   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!