Hi I am learning strings in c. And I stumbled on this errors on Xcode. What I am doing wrong?

#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
    char *colors[3][10] = {'\0'};

    printf("\nEnter 3 colors separated by spaces: ");
    scanf("%s %s %s", colors[0], colors[1], colors[2]);
    //error: format specifies type 'char*' but the argument has 'char**'

    printf("\nYou entered: ");
    printf("%s %s %s\n", colors[0], colors[1], colors[2]);

    return 0;
}

Recommended Answers

All 2 Replies

Check your types, noting that char x[] is identical to char *x. So you can think of char *colors[3][10] as being the same as char ***colors or char colors[][3][10] either way you can see that colors is one level of pointers too deep. Removing the * on line 5 should fix the issue.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.