Can someone tell me what value would each of the line of code will have, when you go through this code:

Here is the full code:
server.conf:

interface=192.168.0.2;
log=/var/log/example;

example.c:

conf_fd=open("/etc/example/server.conf",O_RDONLY);
	read(conf_fd,conf,100);
	close(conf_fd);
	/* Get server IP */
	buffer=strtok(conf,";");
	buffer1=strtok(NULL,";");
	strtok(buffer,"=");
	server=strtok(NULL,"=");
	server_ip=inet_addr(server);

What is the value at these lines?

strtok(buffer,"=");
	server=strtok(NULL,"=");
	server_ip=inet_addr(server);

You seem to have been here long enough to know better than post a title like this. See the Rules.

In looking at your list of threads, STOP using noob/newbie/etc in the title!!! Just use a good name!!!!

conf_fd=open("/etc/example/server.conf",O_RDONLY);
read(conf_fd,conf,100);
close(conf_fd);

This reads the whole content of the file server.conf

/* Get server IP */
buffer=strtok(conf,";");
buffer1=strtok(NULL,";");

This breaks the string into two lines.

strtok(buffer,"=");
server=strtok(NULL,"=");
server_ip=inet_addr(server);

This gets IP address from the second line. To be more precise, in the second line, the things after '=' will be copied to server char *.

And perhaps i wouldn't really appriciate people using strtok function. Rather use fgets and sscanf function to tokensize the string. I guess there should be small tutorial on this web somewhere Dave has explaines about tokenisation of string. Have look at it.

ssharish

This article has been dead for over six months. Start a new discussion instead.