Raised This Month: $ Target: $400
 0% 

How to swap between lines?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 12-29-2012 , 16:33   How to swap between lines?
Reply With Quote #1

I have a file like this format
Code:
[STEAM_ID_1] // SteamId
Noob1 // name
13/9/2012 14:50:49 // last connect time

[STEAM_ID_2]
Noob2
12/9/2012 11:30:12

[STEAM_ID_3]
Noob3
21/12/2012 21:21:21
Let's assume that I'm in the first line, how to go to the second and the third line and read them using fgets() in the same function?

Here is my current code:
Code:
enum _:DATA {     NAME[32],     STEAMID[35],     LAST_CONNECT[50] } public admin_cmd(id, level, cid) {     if(!cmd_access(id, level, cid, 1))         return PLUGIN_HANDLED         CheckFile()         //console_print(id, "# %s %-22.22s %-22.22s", "Name", "SteamId", "Last Connect Time")     server_print("# %-22.22s %-22.22s %s", "Name", "SteamId", "Last Connect Time")         new f = fopen(FILE, "r")         if(!f)         return console_print(id, "Couldn't open file")         new szLine[50], Data[DATA]     while(!feof(f))     {         fgets(f, szLine, charsmax(szLine))                 if(!szLine[0] || szLine[0] == ';' || szLine[0] != '[')             continue;                 replace(szLine, charsmax(szLine), "[", "")         replace(szLine, charsmax(szLine), "]", "")         replace(szLine, charsmax(szLine), "^n", "")                 copy(Data[STEAMID], charsmax(Data[STEAMID]), szLine)         // Here i should get the name and last connection time                 server_print("%d %-22.22s %-22.22s %s", ++i, Data[NAME], Data[STEAMID], Data[LAST_CONNECT])     }         fclose(f)         return PLUGIN_HANDLED }
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-29-2012 , 19:15   Re: How to swap between lines?
Reply With Quote #2

Just use fgets() again. However, you should consider putting all the information on a single line. Also, instead of putting a formatted date in there, you should just use a timestamp and then format that when you need to display it.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-30-2012 , 07:12   Re: How to swap between lines?
Reply With Quote #3

Something like that i guess :

PHP Code:
    while(!feof(f))
    {
        
fgets(fszLinecharsmax(szLine))
        
trimszLine )
        
        if(!
szLine[0] || szLine[0] == ';' || szLine[0] != '[')
            continue;
        
        
replace(szLinecharsmax(szLine), "[""")
        
replace(szLinecharsmax(szLine), "]""")
        
// replace(szLine, charsmax(szLine), "^n", "") // used trim before
        
        
copy(Data[STEAMID], charsmax(Data[STEAMID]), szLine)

        
// Here i should get the name and last connection time
        
fgets(fData[NAME], charsmax(Data[NAME]))
        
trimData[NAME] )
        
        
fgets(fData[LAST_CONNECT], charsmax(Data[LAST_CONNECT]))
        
trimData[LAST_CONNECT] )
        
        
server_print("%d %-22.22s %-22.22s %s", ++iData[NAME], Data[STEAMID], Data[LAST_CONNECT])
    } 
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 13:25.


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