如何从输出中删除不需要的字符 [英] How to remove unwanted characters from output

查看:86
本文介绍了如何从输出中删除不需要的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是将输入字符串中的字符串复制到copystring并输出正确

但输出中有一些不需要的标记,如倒置?,等等



请帮助我新编程



我尝试过:



my code was to copy the string from inputstring to copystring and output was correct
but there were some unwanted signs in the output like inverted ?,", etc

please help me i m new to programming

What I have tried:

#include<stdio.h>
#include<string.h>

int main(){

    char inputstring[100],copystring[100];
    printf("enter the string ");
    gets(inputstring);

    strcat(copystring,inputstring);
    printf("inputstring = %s",inputstring);
    printf("copystring = %s",copystring);


}

推荐答案

strcat 连接字符串。在你的代码中,它将一个可能有效的字符串( inputstring )连接到垃圾( copystring 未初始化)。

如果您只需要输入字符串的副本,请使用 strncpy 而不是 strcat

请注意:永远不要使用获取。改为使用 fgets stdin
strcat concatenates strings. In your code it concatenates a possibly valid string (inputstring) to garbage (copystring is not initialized).
If you just need a copy of the input string, use strncpy instead of strcat.
Please note: never ever use gets. Use fgets with stdin instead.


这篇关于如何从输出中删除不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆