Raised This Month: $ Target: $400
 0% 

Reading Files (skipping lines, etc...)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 10-02-2009 , 00:25   Reading Files (skipping lines, etc...)
Reply With Quote #1

Hey, I have quite a few mods that use files to gather any required information, but I'm having trouble with getting it to skip blank lines properly.

I've tested it and it'll skip the ; fine, just not blank lines - so if you put this in the file.

Code:
; blah blah
thing1


thing2
thing3
thing4
The menu would appear like...

Code:
Menu:

1. thing1
2. thing1
3. thing1
4. thing2
5. thing3
6. thing4
Here's an example of the file...

PHP Code:
// Loads rank configuration settings
LoadRankFile()
{
    
// If file doesn't exist, make one
    
if( !file_exists(ranksfile) )
        
write_file(ranksfile"; Ranks Configuration file^n; Usage: <Rankname> score required>^n; Place in ascending order (i.e. Top rank is the lowest rank)");
    
    
// Set up some vars to hold parsing info
    
new szLine[32], szRankName[16], szScoreNeeded[4];
    
    
// Set max ranks to 0
    
g_MaxRanks 0;
    
    
// Open customization file for reading
    
new file fopen(ranksfile"rt");
    
    while( !
feof(file) )
    {
        
szLine[0] = '^0';
        
        
// Read one line at a time
        
fgets(fileszLine31);
        
        
// Blank line or comment
        
if( szLine[0] == ';' || !szLine[0] ) continue;
        
        else
        {
            
// Seperate the information
            
parse(szLineszRankName15szScoreNeeded3);
            
            
g_ScoreNeeded[g_MaxRanks] = str_to_num(szScoreNeeded);
            
g_szRankName[g_MaxRanks] = szRankName;
            
            
// If line equals hardcoded maximum ranks value, exit the loop
            
if( g_MaxRanks == MAX_BOARDS )
            {
                
log_amx("[SURF-RPG] Reached maximum ranks at ^"%s^"! Increase MAX_RANKS in the script to allow more"szRankName);
                break;
            }
            
            
// Increase ranks
            
g_MaxRanks++;
        }
    }
    
    
// Close the file
    
fclose(file);

Any help would be greatly appreciated.
shadow.hk is offline
Send a message via MSN to shadow.hk
 



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:32.


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