所以我在读从我的C语言编程过程中的一些代码,和对面这个问题问出来:修剪一个字符串,while循环之后为什么会有分号?
修剪字符串:" make trim "
到"make trim"
。 这是代码:
#include <stdio.h>
#include <string.h>
#define MAX 100
void trim(char *s) {
char *d = s;
while (isspace(*s++))
;
s--;
while (*d++ = *s++)
;
d--;
while (isspace(*--d))
*d = 0;
}
int main() {
char s[MAX];
gets(s);
printf("[%s] -> ", s);
trim(s);
printf("[%s]", s);
return 0;
}
所以,我要问的是,什么是
while (isspace(*s++))
;
s--;
while (*d++ = *s++)
;
d--;
while (isspace(*--d))
*d = 0;
递增串(*s++)
,该while()循环后;
做的,又是如何工作?
在此先感谢
只有';'在其他空行上是空的语句。除语法和语义上添加语句外,它什么都不做。 –
如果您想知道它是如何工作的,请了解*指针*,*指针算术*以及如何使用*调试器*在监控变量及其值时逐行浏览代码。 –
感谢您的建议。我目前正在为期末考试进行学习,这是2周后,如果您可以提供一些** C-String **问题汇编或一些很好的字符串(算法)书籍和评论一些链接? –