【发布时间】:2014-03-19 20:16:54
【问题描述】:
我不断收到此错误
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]
当我尝试用 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");
}
}
我一直在尝试解决这个问题,但总是遇到同样的错误。 任何帮助将不胜感激。该程序的目的是打印出这样的一个盒子,给出它的数量和组成它的字符。
./box2 5 #
#####
# #
# #
# #
# #
#####
【问题讨论】:
-
请修正你的缩进!另外,请仔细查看
char c = argv[2]; -
好肉汁,为什么99%的SO代码示例没有缩进???
-
如果缩进得当,他们更有可能注意到他们的错误,而无需发布...