C语言中删除字符串中一个字母,C程序删除字符串中除字母之外的所有字符
时间: 2023-06-23 13:08:56 浏览: 105
删除字符串中一个字母的C程序:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[100], letter;
int i, j;
printf("Enter a string: ");
scanf("%s", str);
printf("Enter a letter to delete: ");
scanf(" %c", &letter);
for (i = 0, j = 0; str[i] != '\0'; i++) {
if (str[i] != letter) {
str[j++] = str[i];
}
}
str[j] = '\0';
printf("Result: %s\n", str);
return 0;
}
```
删除字符串中除字母之外的所有字符的C程序:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i, j;
printf("Enter a string: ");
scanf("%s", str);
for (i = 0, j = 0; str[i] != '\0'; i++) {
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
str[j++] = str[i];
}
}
str[j] = '\0';
printf("Result: %s\n", str);
return 0;
}
```
阅读全文