c语言输出特定类型字符串同时忽略某些字符串的改变
时间: 2024-09-29 22:11:04 浏览: 30
![PDF](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PDF.png)
C语言字符、字符串定义及相关函数
在C语言中,如果你想要输出特定类型的字符串,并且希望忽略某些特定字符或模式的改变,你可以使用`printf`函数配合条件判断来实现。例如,如果你想打印整数型字符串但忽略其中的逗号 `,`,可以这样做:
```c
#include <stdio.h>
#include <string.h>
#define IGNORE_CHAR ','
void print_string_ignoring_commas(char *str) {
int i = 0;
while (str[i] != '\0') { // 遍历字符串直到遇到结尾
if (str[i] != IGNORE_CHAR) {
printf("%c", str[i]); // 如果不是忽略字符,就打印
}
i++;
}
}
int main() {
char num_str[] = "1,234,567";
print_string_ignoring_commas(num_str);
return 0;
}
```
在这个例子中,`print_string_ignoring_commas` 函数会打印出 `num_str` 中除逗号以外的所有字符。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)