I'm a university student. and the teacher wants me to pass multiple strings to function. The answer output is correct but I wonder what the warning is why it shows and how to fix it in my case.
I try to figure it out but so many times I search. It just contains the other case and no one this like my case (using sting with pointer). So if you can additionally recommend me the website that has my case or something with passing 2d array to function I will appreciate it so much.
Here's the code
#include <stdio.h>
#include <string.h>
int hydroxide(char (*message)[100], int size);
int main()
{
char message[6][100] = {"KOH", "H2O2", "NaCl", "NaOH", "C9H8O4", "MgOH"};
int size;
printf("Messages ending with OH are: ");
for(int i = 0; i < 6; i++)
{
size = strlen(message[i]);
if(hydroxide(message[i], size) == 1)
{
printf("%s ", message[i]);
}
}
printf("\n");
return 1;
}
int hydroxide(char (*message)[100], int size)
{
if(((*message)[size - 2] == 'O') && ((*message)[size - 1] == 'H'))
{
return 1;
}
else
{
return 0;
}
}
When I try running it, it shows like this.
HW-4_5_3.c: In function 'main':
HW-4_5_3.c:19:22: warning: passing argument 1 of 'hydroxide' from incompatible pointer type [-Wincompatible-pointer-types]
if(hydroxide(message[i], size) == 1)
^~~~~~~
HW-4_5_3.c:6:5: note: expected 'char (*)[100]' but argument is of type 'char *'
int hydroxide(char (*message)[100], int size);
^~~~~~~~~
Messages ending with OH are: KOH NaOH MgOH
The part that "Messages ending with OH are: KOH NaOH MgOH" is what I want. So, how can I fix it?