Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何替换和编辑字符串中的字符?_C - Fatal编程技术网

C 如何替换和编辑字符串中的字符?

C 如何替换和编辑字符串中的字符?,c,C,这是我的代码: main() { char input[150]; //Create a variable of type char named input to store user input printf(" Enter a standard line: ");

这是我的代码:

main()
{
        char input[150];                                                                        //Create a variable of type char named input to store user input

        printf(" Enter a standard line: ");                                                     //Ask the user for some standard input

        if (fgets(input, 150, stdin) == NULL)                                                   //Initiate a series of checks to make sure there is valid input
        {
                puts(" End-of-File or Input Error Detected. ");                                 //If the end of the file is reached or there is a problem with input output a message
        }
        else if (input[0] == '\n')                                                              //If the user neglected to enter anything output a message
        {
                puts(" Oops! Looks like you forgot to enter something! ");
        }
        else
        {
                printf(" Here's what you entered: %s ", input);                                 //If there is valid user input echo it back to the user

                while (input[0] != '\n')
                {

                       (can I put the while loop here?)
                }
        }
}
我刚刚得到了要运行的代码(由Stackoverflow上的Chux提供),现在我又遇到了另一个问题。现在,我可以验证是否存在输入,我必须相应地替换和调整输入行,方法是用ASCII码替换某些字符,更改字母大小写,并包装行

例如: 1.用户输入:google.COM/search?客户端
2.程序更改并打印回用户:GOOGLE.com%2FSEARCH%3FCLIENT

我该怎么做?我能把while循环留在那里吗

您不应该在(输入[0]!='\n')时使用此-->


假设您的输入[0]等于\n此循环将永远持续,因此请尝试像输入[i]一样执行此操作!='\n'和增加循环中的i

请针对您的问题更具体一些。@kishanoza我认为我非常具体。或者你的意思是我应该举一个例子来说明它应该做什么?没错,请把example@kishanoza可以我举了一个例子。
while(输入[0]!='\n')
总是测试相同的东西。代码可能需要对输入[]进行索引访问。类似于(i=0;输入[i]!='\0';i++){…