Error while passing string in Network Programming in C

Viewed 30

I am implementing an HTTP server from scratch in C where I read a config file to get the path of the required file. But, when I read the file and pass it's value as a string to the function, I don't get Segmentation fault (core dumped) error.

Attaching a few snippets of my code-

char index_loc[20];
char const* const fileName = "config.txt";
    FILE* file = fopen(fileName, "r");
    if(!file){
        printf("\n Unable to open : %s ", fileName);
        return -1;
    }
fgets(index_loc, sizeof(index_loc), file);
setHttpHeader(httpHeader, index_loc);

The function, void setHttpHeader(char httpHeader[], char page[]) is working completely fine when I pass setHttpHeader(httpHeader, "index.html"); to it.

Config file:-

8080
index.html

The port number is being read correctly from the file.

0 Answers
Related