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://codercto.com/courses/l/17.html

查看所有标签

How Great Decisions Get Made

How Great Decisions Get Made

Maruska, Don / 2006-2 / $ 20.28

All too often, solving tough work issues can become a tug of war as clashing departments, priorities, personality styles, and other concerns threaten to destroy any possibility of a successful conclus......一起来看看 《How Great Decisions Get Made》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试