Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:09:23+00:00 2026-06-11T04:09:23+00:00

I am trying out arrays of strings in C. I have a dictionary array

  • 0

I am trying out arrays of strings in C. I have a dictionary array of strings, that I add words to and then print out the array to see if it worked. The output works, as i think it should, printing the words in the array. But I get a number of warnings that I am unable to fix.

// 20 word dictionary
#define ROWS 20
#define WORD_LENGTH 10

char dictionary[ROWS][WORD_LENGTH];

void add_word(char **dict, int index, char *word) {
    dict[index] = word;
}

char *get_word(char **dict, int index) {
    return dict[index];
}

void print_dictionary(char **dict) {
    int i;
    for (i = 0; i < 20; i++) {
        printf("%d: %s\n", i, get_word(dict, i));
    }
}

void test_dictionary() {
    add_word(dictionary, 0, "lorem");
    add_word(dictionary, 1, "ipsum");

    print_dictionary(dictionary);
}

int main() {
    test_dictionary();
}

The output of compiling this is,

p5.c: In function ‘test_dictionary’:
p5.c:54:2: warning: passing argument 1 of ‘add_word’ from incompatible pointer type [enabled by default]
p5.c:38:6: note: expected ‘char **’ but argument is of type ‘char (*)[10]’
p5.c:55:2: warning: passing argument 1 of ‘add_word’ from incompatible pointer type [enabled by default]
p5.c:38:6: note: expected ‘char **’ but argument is of type ‘char (*)[10]’
p5.c:57:2: warning: passing argument 1 of ‘print_dictionary’ from incompatible pointer type [enabled by default]
p5.c:46:6: note: expected ‘char **’ but argument is of type ‘char (*)[10]’

I tried changing **dict to dict[ROWS][WORD_LENGTH] without much difference. Can you guys please explain how to declare this dictionary parameter. Thanks.

Edit: My compiler flags are, CFLAGS = -Wall -g.

Edit2: Changed the declarations to,

void add_word(char dict[][WORD_LENGTH], int index, char *word) {
    dict[index] = word;
}

char *get_word(char dict[][WORD_LENGTH], int index) {
    return dict[index];
}

void print_dictionary(char dict[][WORD_LENGTH]) {
    int i;
    for (i = 0; i < 20; i++) {
        printf("%d: %s\n", i, get_word(dict, i));
    }
}

This gives a compilation error,

p5.c: In function ‘add_word’:
p5.c:42:14: error: incompatible types when assigning to type ‘char[10]’ from type ‘char *’
make[1]: *** [p5] Error 1

Thank you for all your help.

Ah! Figured it out!. Since it’s a pointer, I need to use strcpy as suggested by @Jack.

void add_word(char dict[][WORD_LENGTH], int index, char *word) {
    /*dict[index] = word;*/
    strcpy(dict[index], word);
}

Thanks everyone!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:09:25+00:00Added an answer on June 11, 2026 at 4:09 am

    Root Cause:

    Arrays are not pointers!

    Note that there is no implicit conversion from dict[][] to dict ** and hence the error. When you pass a array to a function, it decays as the pointer to its first element.In case of two dimensional array the first element is an array of single dimenion itself and so you need a pointer to an array and not an double pointer.

    Soultion:

    You need to modify your function prototype to match the type you are passing.

    void add_word(char dict[][WORD_LENGTH], int index, char *word);
    void print_dictionary(char dict[][WORD_LENGTH]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to simply print out the values contained in an array. I have
I'm trying to create arrays from strings that have pipe (|) as delimiters and
I have a character array and I'm trying to figure out if it matches
I am trying to work out a complicated jQuery selection. I have an array,
Hey I have made up a plist file that has an array of strings
I have a multidimensional array built from Strings that is initially created with the
I have the following possible strings that I need to turn into arrays so
I have been trying to return an array of strings for a function for
Trying to get a value out of 2d array inside of a hash and
I'm trying to figure out a way to take a Ruby array and create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.