首页 > 解决方案 > 如何通过用户输入的数字重复我的用户输入的字符串

问题描述

我需要将字符串乘以用户输入的数字。

例如,如果他输入“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);
   }
 } 

但是什么都没有打印出来,我可以寻求帮助吗?

标签: cstring

解决方案


嘿,你有一些错误:

char string[100];//改成指针

scanf("%s", &string);把它改成 --->gets_s(string,100)

for (j = 0; multiply>j; ++j)//改变条件

希望这对你有帮助,祝你以后好运


推荐阅读