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

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 …

Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.