Raised This Month: $ Target: $400
 0% 

Check if the first line in file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mlk27
Veteran Member
Join Date: May 2008
Old 05-11-2009 , 04:19   Check if the first line in file
Reply With Quote #1

Sorry I can't figure this out. How do I check if the first line in a file starts with comments?

Code:
new spawnscredit = 0 while (file && !feof(file)) {     fgets(file, buffer, charsmax(buffer))     trim(buffer)     if(!spawnscredit && (buffer[0] == '/' && buffer[1] == '/')) //     {         spawnscredit = 1         set_task(10.0, "print_spawnscredit", _, buffer, charsmax(buffer))     }         // ..     }
__________________
HLDSWatch - HLDS monitoring and auto restarter script
Mlk27 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-11-2009 , 05:31   Re: Check if the first line in file
Reply With Quote #2

Your code does what you want.
Arkshine is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 05-11-2009 , 07:04   Re: Check if the first line in file
Reply With Quote #3

Doesn't work when the first comments are in other lines, eg

file.txt
de_dust2
dust3
// de_dust2
__________________
HLDSWatch - HLDS monitoring and auto restarter script
Mlk27 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-11-2009 , 08:33   Re: Check if the first line in file
Reply With Quote #4

So reverse the checks.
Arkshine is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-11-2009 , 11:11   Re: Check if the first line in file
Reply With Quote #5

PHP Code:
new spawnscredit 0line 0
 
while (file && !feof(file))
{
    
fgets(filebuffercharsmax(buffer))
    
trim(buffer)
    
line++
 
    if(
line == && (buffer[0] == '/' && buffer[1] == '/')) //
    
{
        
spawnscredit 1
 
        set_task
(10.0"print_spawnscredit"_buffercharsmax(buffer))
    }
 
    
// ..
 


or...

PHP Code:
new bool:spawnscredit false
 
while (file && !feof(file))
{
    
fgets(filebuffercharsmax(buffer))
    
trim(buffer)
 
    if(!
spawnscredit && (buffer[0] == '/' && buffer[1] == '/')) //
        
set_task(10.0"print_spawnscredit"_buffercharsmax(buffer))
 
    
spawnscredit true
 
    
// ..

in wich I guess "spawnscredit" is for that check... if not use above or use this one with different name
__________________
Hunter-Digital is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-11-2009 , 12:17   Re: Check if the first line in file
Reply With Quote #6

No need to create another var. In its code the comment check should be done before spawnscredit check.
Arkshine is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 05-11-2009 , 18:07   Re: Check if the first line in file
Reply With Quote #7

owh. i get it now


Code:
new creditcheck = 0 while (file && !feof(file)) {     fgets(file, linedata, charsmax(linedata))     trim(linedata)     if(!creditcheck)     {         creditcheck = 1                 if(linedata[0] == '/' && linedata[1] == '/')             set_task(10.0, "print_spawnscredit", _, linedata, charsmax(linedata))     } }

kk thanks
__________________
HLDSWatch - HLDS monitoring and auto restarter script

Last edited by Mlk27; 05-11-2009 at 18:10.
Mlk27 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 01:34.


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