加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何替换char中的char *

发布时间:2020-12-16 06:45:32 所属栏目:百科 来源:网络整理
导读:总新手在这里. 我试图替换char *中的字符,但我的程序出错 #include stdio.hint main(int argc,char **argv){ char *mystring ="love is alweys better yoe"; int count = 1; for (count ; count 23; count++) { if ((mystring[count] == 0x65 )) // ((mystri
总新手在这里.
我试图替换char *中的字符,但我的程序出错

#include <stdio.h>

int main(int argc,char **argv)
{
    char *mystring ="love is alweys better yoe";
    int count = 1;

    for (count ;  count < 23; count++)
    {     
    if ((mystring[count] == 0x65 )) //&& ((mystring[count+1] > 0x41) && (mystring[count+1] < 0x7A))) 
    {
      mystring[count] = 0x45; //here occur the freezing
      printf ("%cn",mystring[count]); 
      //break;
    };
    };

    printf("%sn",mystring);
    return 0;
}

解决方法

char *mystring ="love is alweys better yoe"

使mystring只读

您需要先将字符串复制到缓冲区中,然后才能进行更改

例如

char mystring[128];
strcpy( mystring,"love is alweys better yoe" );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读