1234567 是一个字符串省略小数点后两位的数字并且最后还放在字符数组里面提示可以用先找到小数点的方式实现用c语言实现
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "1234.567";
char newStr[10];
int i, j = 0;
for (i = 0; i < strlen(str); i++) {
if (str[i] != '.') {
newStr[j] = str[i];
j++;
} else {
break;
}
}
newStr[j] = '\0';
printf("%s", newStr);
return 0;
}
输出结果:
1234
原文地址: http://www.cveoy.top/t/topic/fn45 著作权归作者所有。请勿转载和采集!