【发布时间】:2014-02-11 13:49:35
【问题描述】:
我需要一个函数来从字符串末尾删除) 字符。
例如,hello,world) 应转换为 hello,world。
我写了这个:
char *a="hello,world)";
int a_len=strlen(a);
*(a+a_len-1)='\0';
printf("%s", a);
但输出中没有显示任何内容。
【问题讨论】:
-
你有一个不错的编译器,它没有
SIGSEGV。 -
@devnull: 为什么编译器会SIGSEGV? ;)
-
@MichaelFoukarakis 你可能想参考this。
-
@devnull:我认为他的意思是 SIGSEGV 发生在运行时而不是编译时
-
@HayriUğurKoltuk 也许吧。我认为 executing 是隐含的。 (执行时)
标签: c string parsing pointer-arithmetic