使用getchar输入字符串
时间: 2023-08-28 11:17:00 浏览: 94
使用getchar输入字符串的方法有多种。以下是两种常见的方法:
方法一:
```c
#include<stdio.h>
int main() {
char str = getchar()) != '\n') {
i++;
}
str[i = '\0'; // 在字符串的末尾加上结束符
printf("你输入的字符串是:%s\n", str);
return 0;
}
```
这种方法会逐个字符读取输入的字符,直到遇到<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [【例3-2】getchar() 字符输入函数](https://blog.csdn.net/zgc_1026999/article/details/122253383)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [c语言之getchar函数输入字符](https://blog.csdn.net/m0_56698546/article/details/127143873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文