谨以此练习来学习最基础的C语言输入和输出。
Description
This is an exercise for you to get prepared for C language programming.
All you have to do is to accept a string as input, and print it character by character. Characters are separated by new line.
The difficulty lies in deciding wether the string ends or not, and 'EOF' is used to solve the problem(see hint).
Input
A string.
Output
Print those characters of the given string, one character per line.
Sample Input
Hi!
Sample Output
H
i
!
HINT
Kernel code:
char ch;
while(scanf("%c",&ch) != EOF) {
// DO SOMETHING
}
#include <stdio.h> //头文件,标准输入输出
#include <stdlib.h>
int main()
{ int ch;
while(scanf("%s",&ch)!=EOF){
printf("%s\n",ch);};
return(0);
本文介绍了一个简单的C语言练习,旨在帮助初学者掌握字符的逐个读取与输出技巧。练习要求从输入中读取一串字符,并将其按字符逐行打印出来。文章提供了示例代码,展示了如何使用while循环结合scanf函数来处理输入直到遇到文件结束符EOF。

被折叠的 条评论
为什么被折叠?



