Raised This Month: $51 Target: $400
 12% 

Getting ip + port from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AwesomeMan
Member
Join Date: Jun 2013
Old 08-05-2013 , 11:00   Getting ip + port from file
Reply With Quote #1

Hello, I want to get ip + port from file into different variables.
By that I mean, i have a file called "ips.txt" and on first line, its:
1.1.1.1:27015
I want to get 1.1.1.1 into a variable let's say ip
and 27015 into variable port.
So ip = 1.1.1.1
port = 27015
Note that i will have more than one ip in file. an example:
1.1.1.1:27015
1.2.3.4:27055
PHP Code:
    new filepointer fopen(filename,"r")
    if(
filepointer)
    {
        new 
parsedip[32]
        new 
readdata[128]
        
        while(
fgets(filepointer,readdata,127))
        {
            
parse(readdata,parsedip,31)
        }
        
fclose(filepointer)
    } 
This is all i could get from reading tutorials.
AwesomeMan is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-05-2013 , 11:34   Re: Getting ip + port from file
Reply With Quote #2

I would use strtok().

Out of curiosity, what are you using the IPs for? I can't think of any good use for an IP.
__________________

Last edited by fysiks; 08-05-2013 at 11:34.
fysiks is offline
AwesomeMan
Member
Join Date: Jun 2013
Old 08-05-2013 , 11:40   Re: Getting ip + port from file
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
I would use strtok().

Out of curiosity, what are you using the IPs for? I can't think of any good use for an IP.
Thanks, I will use strtok. If I have any issue i will post.
Hmm, Im doing it purely for experience. Im still learning and i want to improve.

Last edited by AwesomeMan; 08-05-2013 at 11:44.
AwesomeMan is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-05-2013 , 11:47   Re: Getting ip + port from file
Reply With Quote #4

Quote:
Originally Posted by AwesomeMan View Post
Thanks, I will use strtok. If I have any issue i will post.
Hmm, Im doing it purely for experience. Im still learning and i want to improve.

It's such a small function that a tutorial would not be appropriate for that function alone. However, the function is well documented in the include files:

http://hg.alliedmods.net/amxmodx-cen...tring.inc#l154

If you are trying to learn, I suggest that you don't do anything with IPs (because there is no good use for them). If you want to work with something that uniquely identifies a player, work with SteamIDs.
__________________

Last edited by fysiks; 08-05-2013 at 11:48.
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode