相关疑难解决方法(0)

删除C字符串中所有出现的字符 - 需要示例

InputString : "I am unwell" "We need to go to the doctor" "How long will it take?".

OutputString: I am unwell We need to go to the doctor How long will it take?

该字符串需要清除所有出现的char ".我可以想到以下的认可

  1. 使用,strchr()函数查找第一次出现 "
  2. 将字符串中的所有字符移动一次位置.

重复步骤1和2,直到strchr()返回NULL指针.

我觉得这是解决这个问题的非常低效的方法.我需要知道,如果还有其他方法可以实现这一目标吗?伪代码或实际代码都将受到赞赏.

c string

7
推荐指数
2
解决办法
8737
查看次数

剥去C中字符串的结尾

我需要一个函数来)从字符串的末尾删除字符.例如,hello,world)应该转换为hello,world.

我写了这个:

char *a="hello,world)";
int a_len=strlen(a);
*(a+a_len-1)='\0';
printf("%s", a);
Run Code Online (Sandbox Code Playgroud)

但输出中没有显示任何内容.

c string parsing pointer-arithmetic

-2
推荐指数
1
解决办法
148
查看次数

标签 统计

c ×2

string ×2

parsing ×1

pointer-arithmetic ×1