Hello,

I'm working on a problem and I'm stuck.
<<< BEGIN QUESTION >>>
Write the following function:
Code:
void build_index_url(const char *domain, char *index_url);
domain points to a string containing an Internet domain, such as "knking.com". The function should add "http://www." to the beginning of this string and "/index_html" to the end of the string, storing the result in the string pointed to by index_url. (In this example, the result will be "http://www.knking.com/index.html".) You may assume that index_url points to a variable that is long enough to hold the resulting string. Keep the function as simple as possibleby having it use the strcat and strcpy functions.
<<< END QUESTION >>>

Code:
#include <stdio.h>
#include <string.h>
// http://knking.com/books/c2/answers/c13.html


void build_index_url(const char *domain, char *index_url);


int main(){
    const char dom[]="knking.com";
    char url[50];
    build_index_url(dom, url);
    printf("url = %s\n", url);  // prints: url = 
    return (0);
}


void build_index_url(const char *domain, char *index_url){
    char preBuild[20]="http://www.";
    char postBuild[20]="/index.html";
    char newBuild[20];
    strcat(preBuild, domain);
    strcat(preBuild, postBuild);
    strcpy(index_url, preBuild);    // put data in location pointed to by index_url
    printf("function: index_url = %s\n", index_url);  // works fine
}
In the build_index_url function, I assumed that index_url was pointing to url as it was defined in main(). The problem: when the program returns to main(), I can't get url to print "http://www.knking.com/index.html". What an I not understanding?