A
aqazi
Hi folks
I am trying to write a program which acts like a p2p server. When the
program starts it reads a file from whereit will read broadcast IP
address, port and another port number. Now I am trying skip the
comments and empty lines by saying if there is newline or # sign at the
first charecter of a line then to skip the line.But the problem is the
program is not working.
I am using the following code:
line = malloc(sizeof (char) *SIZE_OF_LINE);
while(fgets(line, SIZE_OF_LINE + 1, fp) != NULL)
{
i f(line[0] != '#' || line[0] != '\n')
{
fprintf(stderr,"i am here\n");
fprintf(stderr,"%s", line);
strcpy(tmpEntry, strtok(line, ":"));
strcpy(tmpValue, strtok(NULL, "\n"));
fprintf(stderr,"\t%s", tmpEntry);
fprintf(stderr,"\t: %s\n", tmpValue);
}
}
and the file the program is reading is:
#############################################################################
# P2P Conf File
#Please Don't modify this file as this is file is used to
#create all required sockets
# Author : Ahetesham Qazi
#############################################################################
Brodcast_IP:192.168.1.255
Brodcast_Port:30001
Comm_Port:30101
The program should skip the first seven lines but the problem it's not
skipping. and when it's trying to tokenize the first line and then
printing it it's giving me segmentation fault.
Any suggetion would be greatly appreciated
Thanks
Ahetesham Qazi
I am trying to write a program which acts like a p2p server. When the
program starts it reads a file from whereit will read broadcast IP
address, port and another port number. Now I am trying skip the
comments and empty lines by saying if there is newline or # sign at the
first charecter of a line then to skip the line.But the problem is the
program is not working.
I am using the following code:
line = malloc(sizeof (char) *SIZE_OF_LINE);
while(fgets(line, SIZE_OF_LINE + 1, fp) != NULL)
{
i f(line[0] != '#' || line[0] != '\n')
{
fprintf(stderr,"i am here\n");
fprintf(stderr,"%s", line);
strcpy(tmpEntry, strtok(line, ":"));
strcpy(tmpValue, strtok(NULL, "\n"));
fprintf(stderr,"\t%s", tmpEntry);
fprintf(stderr,"\t: %s\n", tmpValue);
}
}
and the file the program is reading is:
#############################################################################
# P2P Conf File
#Please Don't modify this file as this is file is used to
#create all required sockets
# Author : Ahetesham Qazi
#############################################################################
Brodcast_IP:192.168.1.255
Brodcast_Port:30001
Comm_Port:30101
The program should skip the first seven lines but the problem it's not
skipping. and when it's trying to tokenize the first line and then
printing it it's giving me segmentation fault.
Any suggetion would be greatly appreciated
Thanks
Ahetesham Qazi