I have a text file containing several lines of IP's and Ports with 3 sets per line.

For example:

IP1=1.2.3.4 PRT1=100 IP2=2.3.4.5 PRT2=200 IP3=3.4.5.6 PRT3=300
IP1=12.34.56 PRT1=1000 IP2=2.3.4.5 PRT2=200 IP3=3.4.5.6 PRT3=300

I want to read in each line, see if PRT1 matches a specific port, if so then print out IP2 and PRT2.

So far I have it reading in a line, and then matching PRT1 (I just check to see if the line contains 'PRT1=x' using strstr).

However I am not sure how to get the values of IP2 and PRT2 as I dont know how to extract unknown values (as we do not know what we are looking for unlike finding PRT1) and these values are not restricted to being a certain length.

Can anyone advise me on how to do this?

Thanks in advance :)

I used strtok with " " so each token was on a new line and then searched each token to see if it contained 'IP2' 'PRT2', etc and it works, thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.