所以这是我的代码:
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?client
2.程序更改并打印回用户:GOOGLE.com%2FSEARCH%3FCLIENT
我该怎么做?我可以将while循环留在原处吗?
答案 0 :(得分:0)
你不应该使用这个----> while(输入[0]!=' \ n');
让我们说你的输入[0]等于\ n这个循环永远持续,所以也许尝试像输入[i]!=' \ n'并增加循环中的i