c - 如何通过用户输入的数字重复我的用户输入的字符串
问题描述
我需要将字符串乘以用户输入的数字。
例如,如果他输入“hello”并输入 3,则必须显示hellohellohello
int multStr() {
char string;
int multiply = 0;
int j;
printf("enter a string please");
scanf("%s", & string);
printf("now multiply your string");
scanf("%d", & multiply);
for (j = 0; multiply == !j; ++j) {
printf("%s", string);
}
}
但是什么都没有打印出来,我可以寻求帮助吗?
解决方案
嘿,你有一些错误:
char string[100];//改成指针
scanf("%s", &string);把它改成 --->gets_s(string,100)
for (j = 0; multiply>j; ++j)//改变条件
希望这对你有帮助,祝你以后好运
推荐阅读
- reactjs - React - 在 Redux-Form 中初始化值会导致多个警告消息
- c# - 如何统一销毁Button
- http-status-code-404 - Github pages 站点返回 404 Page Not Found
- function - Haskell 检查空列表
- java - 为什么下面的结果是输出?类字段在构造函数之前没有被初始化吗?
- java - 如何在java中读取没有换行符的数据集
- rust - 惯用地将值从一个 Vec 移动/排序到另一个
- python - 如何将我的条形标签移动到它们分别代表的条形末尾?
- wordpress - 迁移服务器后,我的网站无法正常工作
- operating-system - 无论日志中的值更改为什么,我都需要一个 grok 模式来仅保留红色概述的信息