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

read first line from the file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 07-02-2022 , 04:41   read first line from the file
Reply With Quote #1

How do I return the first line
PHP Code:

public GetData(){
    new 
Handle:matchFile OpenFile(g_sFilePath"r");
    new 
String:lineBuffer[128];
    
// Reads an opened file one line at a time into specified buffer
    
ReadFileLine(matchFilelineBuffersizeof(lineBuffer));
    
// Print out contents of first line on the server
    
PrintToServer("First line in file:\n%s"lineBuffer);
    
    
CloseHandle(matchFile);
    
    return 
lineBuffer;

File:- data.ini
PHP Code:
first text line to save in a variable 
__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 07-03-2022 , 06:00   Re: read first line from the file
Reply With Quote #2

Try this way:
PHP Code:
stock String:GetData()
{
    
decl String:buffer[PLATFORM_MAX_PATH];
    
// file location relative to folder .../addons/sourcemod/
    
BuildPath(Path_SMbuffersizeof(buffer), "data.ini");

    new 
Handle:file OpenFile(buffer"r");
    if(
file)
    {
        
// Reads an opened file one line at a time into specified buffer
        
ReadFileLine(filebuffersizeof(buffer));
        
// Print out contents of first line on the server
        
PrintToServer("First line in file:\n%s"buffer);

        
CloseHandle(file);

        return 
buffer;
    }
    else 
PrintToServer("Unable to open file \"%s\""buffer);

    
buffer[0] = 0;
    return 
buffer;

__________________
Grey83 is offline
Reply


Thread Tools
Display Modes

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 05:59.


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