ai didi

c - 用空字符替换 "\""

转载 作者:行者123 更新时间:2023-11-30 18:20:01 24 4
gpt4 key购买 nike

我需要用空字符“”替换“(ASCII值34)字符”。

在输出中,我得到的不是引号而是“?”问号字符。我尝试使用以下内容:

mystring[itit] = "";

mystring[itit] = '';

mystring[itit] = "\O";

我的代码:

strcpy( mystring ,op->data.value.str  );
for(itit=0;itit<10;itit++)
{
if(mystring[itit] == 34)
{
mystring[itit] = NULL;
}


}
printf( "%s\n",mystring);

有什么想法可以解决这个问题吗?

澄清一下:mystring 中的字符串如下所示:

“你好”

“地点”

“学校”

全部带有引号 - 我实际上需要删除它们并得到:

你好

地点

学校

最佳答案

int removeChar(char *str, char c) {

int i, j;

for(i = 0, j = 0 ; str[i] ; i++){
if( str[i] == c) continue; // skip c do not copy it
str[j] = str[i]; // shift characters left
j++;
}
str[j]=0; // terminate the string
return j; // return the actual size
}

关于c - 用空字符替换 "\"",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723981/

24 4 0
文章推荐: c - 指针变量存储什么?
文章推荐: C - 是否有可能有一个返回 char * 或 int 的函数?
文章推荐: javascript - 除非单击特定元素,否则触发模糊事件
文章推荐: c - 在C中,在 'if'语句中,为什么要反转test的常量和变量,例如如果(10==val){}?
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com