
printf没有为格式字符串传递足够的参数
缺少printf的整型参数
下午好🌅🌅🌅
本答案参考ChatGPT-3.5
#include<stdio.h>
void foo() {
int i = 1;
for (i = 1; i <= 10; i++) {
printf("Hello World\n");
}
}
int main() {
int n;
printf("Enter the length of the string: ");
scanf("%d", &n);
printf("Enter the width of the string: ");
scanf("%d", &n);
foo();
return 0;
}
这段代码有一个未初始化的变量foo()。您需要在调用foo()之前设置其值。
您可以使用以下修改过的代码:
#include<stdio.h>
#include<unistd.h>
#include<string.h>
void foo() {
int i = 1;
for (i = 1; i <= 10; i++) {
printf("Hello World\n");
}
}
int main() {
int n;
printf("Enter the length of the string: ");
scanf("%d", &n);
foo();
return 0;
}
在此版本中,我们包含了unistd.h和string.h头文件,以便能够使用函数scanf()来读取输入流,并使用函数strlen()来获取字符串的长度。
此外,我们还引入了stdio.h和unistd.h,因为它们提供了与scanf()和strlen()函数相关的主要功能。