删除列的文字

编程入门 行业动态 更新时间:2024-10-27 12:31:48
本文介绍了删除列的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图写一个code,要求用户输入一个字符串,并采取所有字符,除了字母。

现在我做到了我自己,它似乎并没有正常工作。我是新来的字符串所以我想了解和掌握字符串。我试图在Mac上使用gdb的,但我没有所有的功能明白这一点。能否请你帮忙吗?

什么是code必须做到:用户输入(例如):ħ**#EL(L)的O& ^ W

和输出你好。

这是我的code:

的#include<&stdio.h中GT;#包括LT&;&string.h中GT;诠释的main(){   字符字符串[100];   INT I;   诠释看出= 0;   的printf(请输入字符串:);   scanf函数(%S,字符串);   对于(i = 0;字符串[我] ='\\ 0';!我++)   {       如果(((字符串[1] - ='A'||字符串[I]>Z)及及(字符串[1] - ='A'||字符串[I]>' Z'))||字符串[I]!='\\ 0')       {           看出= 1;       }       其他           看出= 0;   }   如果(看到== 0)   {       的printf(%S,字符串);   }}

解决方案

任何部分(除去多余的字符),以改变你code中的字符串。

的#include<&stdio.h中GT;#包括LT&;&string.h中GT;#包括LT&;&文件ctype.h GT;字符*过滤器(字符*字符串,INT(*测试)(INT)){    字符*从*到;    对于(从字符串= =; *从++从){        如果(测试(* FROM))            *为++ = * FROM;    }    *为='\\ 0';    返回的字符串;}诠释主(){    字符字符串[100];    的printf(请输入字符串:);    scanf函数(%99秒,字符串);    的printf(%S \\ n,过滤器(串,因而isalpha));    返回0;}

I'm trying to write a code that asks the user to enter a string and takes of all characters except the alphabetical.

Now i did it myself and it doesn't seem to work properly. I'm new to strings so i'm trying to understand and master strings. I tried to use gdb on mac but i don't have all the functions to understand this. Could you please help?

What the code must do: User inputs (for example): h**#el(l)o&^w

and the output is hello.

here is my code:

#include <stdio.h> #include <string.h> int main() { char string[100]; int i; int seen = 0; printf("Enter String: "); scanf("%s", string); for (i=0; string[i]!='\0'; i++) { if (((string[i]<='a' || string[i]>'z')&&(string[i]<='A' || string[i]>'Z')) ||string[i]!='\0') { seen = 1; } else seen = 0; } if (seen==0) { printf("%s", string); } }

解决方案

No part(remove the extra characters) to change the string in your code.

#include <stdio.h> #include <string.h> #include <ctype.h> char *filter(char *string, int (*test)(int)) { char *from, *to; for(to = from = string;*from;++from){ if(test(*from)) *to++ = *from; } *to = '\0'; return string; } int main(){ char string[100]; printf("Enter String: "); scanf("%99s", string); printf("%s\n", filter(string, isalpha)); return 0; }

更多推荐

删除列的文字

本文发布于:2023-10-17 03:01:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1499584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!