'fscanf reads string but when I copy string to array it modifies the whole array

I have this code. This is the file content

nasa.txt
news1.txt
file11.txt
mixed.txt
planets.txt
file21.txt
info31.txt

This is the code

    FILE *fp = fopen(collectionFilename, "r");

    char url[MAX_WORD + 1];
    char *urls[MAX_WORD + 1];

    while(fscanf(fp, "%s", url) == 1){
        urls[index++] = url;
    }

    for(int i = 0; i < index; i++){
        printf("%s\n", urls[i]);
    }
    fclose(fp);

I want the code to read in the file names and store them into my urls array. However my printf statement at the end prints info31.txt 7 times and I'm a bit confused as to why this happens.

Thank you!

c


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source