angry somoan angry somoan - 11 days ago 6
C Question

passing argument 1 of ‘function_name’ makes pointer from integer without a cast

So here's code:

#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);
}


What I'm trying to do here, is to get the length of a string and use this value as a parameter in another function responsible for printing as many characters in a row, as there are characters is in given string. But I get an error at line 19: (passing argument 1 of ‘drawName’ makes pointer from integer without a cast).. I've read all the questions simiar to this one here on stackoverflow, but still can't make it work. I'd appreciate your help a lot! I'm at a dead end here...

Answer

The function

void drawName(char nameLetter[], char brush);

is declared with the first parameter of type char *

While you are calling it with an argument of type char.

char brush, name;
^^^^^^^^^^^^^^^^
//...            
drawName(name, brush);