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

查看所有标签

Blockchain Basics

Blockchain Basics

Daniel Drescher / Apress / 2017-3-16 / USD 20.99

In 25 concise steps, you will learn the basics of blockchain technology. No mathematical formulas, program code, or computer science jargon are used. No previous knowledge in computer science, mathema......一起来看看 《Blockchain Basics》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具