C语言去除字符串前导空格
可以使用循环遍历字符串,每次判断当前字符是否为空格,如果是则继续遍历下一个字符,直到找到第一个非空格字符。
示例代码:
#include <stdio.h>
#include <string.h>
int main() {
char str[] = ' hello world';
char *p = str;
// 跳过前面的空格
while (*p == ' ') {
p++;
}
printf('%s', p); // 输出 'hello world'
return 0;
}
原文地址: https://www.cveoy.top/t/topic/l0kM 著作权归作者所有。请勿转载和采集!