簡體   English   中英

C 程序帶回車 \r

[英]C program with return carriage \r

如何編寫一個 C 程序,允許我為輸入中的每個空格進行回車?

例如:

輸入:“我喜歡編程”

Output:

I 
love
programming

我做了什么:

#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;
}

讀一個字符。 如果是空格,打印一個'\r'

#include <ctype.h>

int ch;
while ((ch = getchar()) != EOF) {
  putchar(isspace(ch) ? '\r' : ch);
}

或者如果你想要一個新行

  putchar(isspace(ch) ? '\n' : ch);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM