C 语言实例 - 删除字符串中的特殊字符
C 语言教程
· 2019-02-21 08:43:35
删除字符串中的除字母外的字符。
实例
#include<stdio.h>
int main()
{
char line[150];
int i, j;
printf("输入一个字符串: ");
fgets(line, (sizeof line / sizeof line[0]), stdin);
for(i = 0; line[i] != '\0'; ++i)
{
while (!( (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') || line[i] == '\0') )
{
for(j = i; line[j] != '\0'; ++j)
{
line[j] = line[j+1];
}
line[j] = '\0';
}
}
printf("输出: ");
puts(line);
return 0;
}
输出结果为:
输入一个字符串: run4#$1oob 输出: codercto
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
Algorithms to Live By
Brian Christian、Tom Griffiths / Henry Holt and Co. / 2016-4-19 / USD 30.00
A fascinating exploration of how insights from computer algorithms can be applied to our everyday lives, helping to solve common decision-making problems and illuminate the workings of the human mind ......一起来看看 《Algorithms to Live By》 这本书的介绍吧!