我一直收到这个错误
box2.c: In function 'printchars':
box2.c:26:4: warning: passing argument 1 of 'printf' makes pointer from integer without a
cast [enabled by default]
/usr/include/stdio.h:363:12: note: expected 'const char * __restrict__' but argument is
of type 'char' box2.c:26:4: warning: format not a string literal and no format arguments [-Wformat-security]
box2.c:39:8: warning: passing argument 1 of 'printf' makes pointer from integer without a cast [enabled by default]
/usr/include/stdio.h:363:12: note: expected 'const char * __restrict__' but argument is of type 'char'
box2.c:39:8: warning: format not a string literal and no format arguments [-Wformat-
security]
Run Code Online (Sandbox Code Playgroud)
当我尝试用gcc编译这个程序时
#include <stdio.h>
void printchars(char c, int n);
int main( int argc, char*argv){
int n = argv[1];
char c = argv[2];
int nn = atoi(n);
printchars(c, nn);
return 0;
}
void printchars(char c, int n){
int x;
for (x = n + 2 ; x > 0; x--){
if (x != 1 && x != n){
printf(c);
int count = n;
while (count - 2 != 0){
printf(" ");
count--;
}
}
else{
int num = n;
while (num != 0){
printf(c);
num--;
}
}
printf("\n");
}
}
Run Code Online (Sandbox Code Playgroud)
我一直试图弄清楚,但一直得到同样的错误.任何帮助将不胜感激.该程序旨在打印出一个这样的框,给出了多少和制作它的角色.
./box2 5 #
#####
# #
# #
# #
# #
#####
Run Code Online (Sandbox Code Playgroud)
这里
printf(c);
Run Code Online (Sandbox Code Playgroud)
你将字符而不是格式字符串作为第一个参数传递给printf().它应该是
printf("%c", c);
Run Code Online (Sandbox Code Playgroud)
或者
putchar(c);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27227 次 |
| 最近记录: |