[英]C program with return carriage \r
How do I write a C program that allows me to make carriage return for each white space in the Input?如何编写一个 C 程序,允许我为输入中的每个空格进行回车?
Like for example:例如:
Input: "I love programming"输入:“我喜欢编程”
Output: Output:
I
love
programming
What I did:我做了什么:
#include<stdio.h>
#include <ctype.h>
int main() {
int ch;
char str[50];
while ((ch = getchar()) != EOF) {
putchar(isspace(ch) ? '\r' : ch);
}
scanf("%s", str);
printf("%s", str);
return 0;
}
Read a character.读一个字符。 If a white space , print a
'\r'
如果是空格,打印一个
'\r'
#include <ctype.h>
int ch;
while ((ch = getchar()) != EOF) {
putchar(isspace(ch) ? '\r' : ch);
}
Or if you want a new line :或者如果你想要一个新行:
putchar(isspace(ch) ? '\n' : ch);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.