Click here to Skip to main content
15,920,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Solved...

XML
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
Posted
Updated 28-Feb-15 0:03am
v2

As per the code it seems like IP address and port is stored in a configruation file named IP_CONFIG.txt. In order to correctly use IP_CS and PORT_CS variables you need to correctly define these settings in the configuration file.

You can get a good understanding by stepping into the code in debug mode and exactly see what is going inside the program which will be a great learning experience.
 
Share this answer
 
Comments
Member 10381372 24-Feb-15 6:57am    
If i use this after assigning IPS and Ports
<pre lang="c++">
printf("The IPs are \n %s\n %s\n %s\n %s\n %s\n %s\n",IP_CS,IP_HMI,IP_OBCU,IP_ASR,IP_RSO,IP_RSO_D);
printf("The PORTSs are \n %d\n %d\n %d\n %d\n %d\n %d\n",PORT_CS,PORT_HMI,PORT_OBCU,PORT_ASR,PORT_RSO,PORT_RSO_D);
</pre>
I get the follwing response. That means it is showing exactly the required assignements

<pre lang="c++">

Now printing each saved string:
The IPs are
"192.168.128.3"
"192.168.128.2"
"192.168.128.1"
"192.168.128.4"
"127.0.0.1"
"127.0.0.1"
The PORTSs are
1901
1901
1901
3567
4444
7777

checked1
checked2
checked3

</pre>
Member 10381372 24-Feb-15 14:05pm    
@_Asif_ Please check the above output. If i am getting this output using the same variables what can be wrong inside IP_CONFIG.txt???
In debug mode, I don't see any error.
May be I'm wrong, but for me, it looks like you are freeing the memory before assigning the variables like IP_CS.

You should free the memory, when you don't need it anymore.

C++
printf("\nNow printing each saved string:\n");
    for (jj=0; jj<ii;>        printf("String %d: %s\n", jj, allwords[jj]);
// freeing the memory:
        free(allwords[jj]);
        }

// trying to acces freed memory!?
   char * IP_CS   = allwords[0];    
   char *IP_HMI   = allwords[2];   
   char *IP_OBCU  = allwords[4];      
   char *IP_ASR   = allwords[6];      
   char *IP_RSO   = allwords[8];      
   char *IP_RSO_D = allwords[10]; 
   
   int PORT_CS   = atoi(allwords[12]);
   int PORT_HMI   = atoi(allwords[14]); 
   int PORT_OBCU   = atoi(allwords[16]);
   int PORT_ASR   = atoi(allwords[18]);
   int PORT_RSO   = atoi(allwords[20]);
   int PORT_RSO_D = atoi(allwords[22]);


BTW: I hope this is just a short test program. Otherwise you should structure your code a bit more with functions like LoadSettings(), SetUpSockets() etc.
 
Share this answer
 
v2
Comments
Member 10381372 24-Feb-15 6:50am    
I checked with commenting that section but i find the same. :(
Andy411 24-Feb-15 7:28am    
Did you try to comment out the free() or better putting the for-loop with the fre() at the end of you program?
Member 10381372 24-Feb-15 14:02pm    
Even its the same even if you don't consider this for loop

for (jj=0; jj<ii;> printf("String %d: %s\n", jj, allwords[jj]);
// freeing the memory:
free(allwords[jj]);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900