while((tem=getchar())!='\n')
时间: 2023-09-21 09:04:50 浏览: 43
This code reads characters from standard input until it encounters a newline character. The getchar() function is used to read a single character at a time, and the while loop continues to execute as long as the character read is not a newline character ('\n'). Once a newline character is encountered, the loop terminates and the program moves on to the next line of code. The value of the last character read is stored in the variable 'tem'.
相关问题
C. for(;a=getchar!='\n';)
这段代码有一个小错误,应该是`a=getchar()`而不是`a=getchar`。正确的代码是:
```c
for(; (a = getchar()) != '\n'; ) {
// 循环体
}
```
这是一个C语言中的for循环语句,它的循环条件部分没有设置循环变量和循环次数,因此它会一直循环下去,直到遇到换行符`\n`为止。在每次循环中,通过`getchar()`函数获取一个字符并赋值给变量a,然后判断该字符是否为换行符。如果不是,则继续循环执行;如果是,则跳出循环。这个循环可以用于读取用户从键盘输入的一行字符串,并将其存储到一个字符数组中。
for(;a=getchar!='\n';)
这是一个C语言中的for循环语句,它的循环条件部分没有设置循环变量和循环次数,因此它会一直循环下去,直到遇到换行符`\n`为止。在每次循环中,通过`getchar()`函数获取一个字符并赋值给变量a,然后判断该字符是否为换行符。如果不是,则继续循环执行;如果是,则跳出循环。这个循环可以用于读取用户从键盘输入的一行字符串,并将其存储到一个字符数组中。