AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   read first line from the file (https://forums.alliedmods.net/showthread.php?t=338395)

Sanjay Singh 07-02-2022 04:41

read first line from the file
 
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 


Grey83 07-03-2022 06:00

Re: read first line from the file
 
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;




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

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