【发布时间】:2016-11-25 18:57:06
【问题描述】:
下面是代码:
#include <stdio.h>
#include <stdlib.h>
void draw(int length, char brush);
int stringLength(char name[]);
void drawName(char nameLetter[], char brush);
int length;
char brush, name;
char *a = "Anne", *b = "Bart", *c = "Celine", *d = "Darius";
int main(void) {
printf("Write down the length of line.\n");
scanf("%d", &length);
printf("Give first letter of the name (a, b, c albo d)\n");
scanf(" %c", &name);
printf("Pick character to be used as brush.\n");
scanf(" %c", &brush);
drawName(name, brush);
return 0;
}
void draw(int length, char brush) {
int i;
for (i = 0; i < length; i++) {
printf("%c", brush);
}
}
int stringLength(char name[]) {
int i;
while (name[i] != '\0') {
i++;
}
return i;
}
void drawName(char nameLetter[], char brush) {
draw(stringLength(nameLetter), brush);
printf("%s\n", nameLetter);
draw(stringLength(nameLetter), brush);
}
我在这里尝试做的是获取字符串的长度并将该值用作另一个函数中的参数,该函数负责连续打印尽可能多的字符,因为给定字符串中有字符。但是我在第 19 行收到一个错误:(传递 'drawName' 的参数 1 使指针从整数而不进行强制转换).. 我已经在 stackoverflow 上阅读了与此问题类似的所有问题,但仍然无法使其工作.非常感谢您的帮助!我这里是死胡同……
【问题讨论】:
-
drawName将char *作为其参数(从char []衰减)。您的代码显然传递了一个char参数。这有什么不明白的? -
在
stringLength()中你未能初始化i。
标签: c function parameters declaration