Click here to Skip to main content
15,607,524 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The words_ptr[i] = &words[i] doesn't work.
It says that it cannot convert from 'char(*_w64)[10] to 'char'

#define NUM_STRINGS 10
#define STR_LEN 10
int main (void) {
    char words[NUM_STRINGS][STR_LEN];
    char input[STR_LEN];
    char *words_ptr[NUM_STRINGS];
    char *temp;
    int i, j;
    int count = 0;
    for (i = 0; i < NUM_STRINGS; ++i) {
        printf("Enter a word (or 0 to quit): ");
        scanf ("%9s", input);
        if (input[0] == '0') break;
        strncpy(words[i], input, STR_LEN);
        words_ptr[i] = &words[i];  //mistake

You do not need an ampersand: words is a two-dimensional array, so it behaves a lot like an array of pointers.
Share this answer
True! You can't assign it that way.
But you can cast the pointer before assigning it.
words_ptr[i] = (char*)&words[i]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900