sofia
sofia

Reputation: 19

Why do I get the error: argument of type "int" is incompatible with parameter of type "char*" in C?

I am trying to print the keys (the char) on a display, I have programmed both keypad and display. I am trying now to let the user write the time using the keyboard and it should print the time if it is valid.

I am currently trying to create a function that prints the time on a display. I have implemented a function called printArray(char Arr[]) that looks like this:

void printArray(char Arr[]) {
  int n = 0;
  while(Arr[n] != 0){
    printkeys(Arr[n]);
    n++;
  }
}

the printkeys method prints writes the numbers into ascii code (made it in previous project and it works)

my time function I want to print looks like this:

void Timettt(char Arr[], char x, char y){
  printArray((Arr[0]/10 + ASCIIOFFSET));
  printArray((Arr[0]%10 + ASCIIOFFSET));
  putchar(':');
  printArray((Arr[1]/10 + ASCIIOFFSET));
  printArray((Arr[1]%10 + ASCIIOFFSET));
  putchar(':');
  printArray((Arr[2]/10 + ASCIIOFFSET));
  printArray((Arr[2]%10 + ASCIIOFFSET));
}

When I compile the code I get error on the printArray parts in Timettt function saying: argument of type "int" is incompatible with parameter of type "char*"

I have no idea why it shows up when all my functions inclusive the print keys function are void and with the argument type char.

I would gladly accept any help/tips you can give

I have tried to compile it and change the Timettt function in other ways but I still get the same error

Upvotes: 1

Views: 159

Answers (1)

Willis Hershey
Willis Hershey

Reputation: 1574

char Arr[] is a pointer to an array of char, so Arr[0] is a char.

a char divided by ten and added to (what I have to assume is) a numerical constant is an int due to integer promotion rules for integer types representable by int.

I have no idea why you are trying to do, but what your code says is you want to pass an integer value to a function that is expecting a pointer to a char array, which makes no sense, which is why your compiler is complaining.

Upvotes: 2

Related Questions