Home >Backend Development >C#.Net Tutorial >c language to delete numeric characters in string

c language to delete numeric characters in string

王林
王林Original
2020-05-10 15:14:1210880browse

c language to delete numeric characters in string

目的:

C语言实现删除字符串s中的数字字符。

具体代码如下:

// 删除数字
#include <stdio.h>
#define N 100
int main(void)
{
	char s[N];
	int j,k;
	gets(s);// 输入字符串
	for(j = k = 0;s[j]!=&#39;\0&#39;;j++)// 此循环用于删除字符串中的数字
		if(s[j]<&#39;0&#39;||s[j]>&#39;9&#39;)
			s[k++] = s[j];
	s[k] = &#39;\0&#39;;// 处理过的字符串加上结束标志&#39;\0&#39;
	puts(s);// 输出处理过的字符串
	return 0;
}

输出结果:

c language to delete numeric characters in string

推荐教程:c语言教程

The above is the detailed content of c language to delete numeric characters in string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn