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++){…