similar to 'Loading Variables from Text File in C++' but in C instead of c++
i want to have a main program that acts as a web server and then the webserver.conf file which loads variables. basically webserver.conf will determine how the web server acts (for example when a GET request is received)
variables such as
hostname = 127.0.0.1
port = 80
etc...
i understand the concept of fopen fclose and the basic C functions for reading a file, but still learning about these and i can't find much on the net about reading and setting variables from a file.
Could anyone provide a very simple example where a C program, sort of started below with a super simple fopen for a file.
int main(void) {
FILE *fp;
char *mode = "r";
fp = fopen("/home/lewis/Documents/config/webconfig.conf", mode);
if (fp == NULL) {
fprintf(stderr, "Can't open input file webconfig.conf!\n");
exit(1);
return (EXIT_SUCCESS);
}
}
the context is i want to use a GET command and then print the result (config file)
sorry that the purpose seems skewed... i'll try to apply logic..
main web server
loads webconfig (should be default file to load for GET) to set internal variables
determines action for receiving a GET command
receieves GET command from keyboard
Checks file that is requested
opens file, reads contents
prints contents to stdout
i understand there will be multiple files for each different function, file handling, input handling etc...
just need a bit of a push in the right direction as tying to learn and wrap my head around it.
****DO NOT NECESSARILY WANT CODE, SIMPLY A LOGIC AND UNDERSTANDING OF HOW A C PROGRAM LIKE THIS WOULD COME TOGETHER*****
thanks