c语言怎么输入字符串

1个回答

写回答

ZhouWei2

2022-11-19 15:27

+ 关注

可以使用scanf或fgets函数来输入字符串。

使用scanf函数输入字符串示例:

char str[100];

printf("请输入字符串:");

scanf("%s", str); //从标准输入读取字符串,存储到str数组中

printf("你输入的字符串是:%s\n", str);

使用fgets函数输入字符串示例:

char str[100];

printf("请输入字符串:");

fgets(str, 100, stdin); //从标准输入读取字符串,存储到str数组中,最多读取100个字符

printf("你输入的字符串是:%s\n", str);

举报有用(17分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号