Raised This Month: $ Target: $400
 0% 

Solved Add character in existing line


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-14-2018 , 07:06   Re: Add character in existing line
Reply With Quote #1

There's a problem though, even with that stock, how am I supposed to add a character at the start of the text? If I replace " with ;" it will be like this
PHP Code:
;"Donii;" 
Meanwhile it should be like this
PHP Code:
;"Donii" 
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-14-2018 , 07:10   Re: Add character in existing line
Reply With Quote #2

Quote:
Originally Posted by edon1337 View Post
There's a problem though, even with that stock, how am I supposed to add a character at the start of the text? If I replace " with ;" it will be like this
PHP Code:
;"Donii;" 
Meanwhile it should be like this
PHP Code:
;"Donii" 
That's basic string manipulation, nothing to do with files.
1.Shift all cell's content one position to the right and then overwrite the first one.
2.Use formatex in another string, like formatex(..., ..., ";%s", Line).
3.Use strcat.
__________________

Last edited by HamletEagle; 08-14-2018 at 07:10.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-14-2018 , 07:25   Re: Add character in existing line
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
That's basic string manipulation, nothing to do with files.
1.Shift all cell's content one position to the right and then overwrite the first one.
2.Use formatex in another string, like formatex(..., ..., ";%s", Line).
3.Use strcat.
I totally forgot about formatex

Is NewLine[] purposely not used or you just forgot?
PHP Code:
stock RemoveLine(const FileName[], const OldLine[], const NewLine[])
{
    new const 
TempFileName[] = "tempfile.ini"

    
new ConfigDirPath[128]; get_configsdir(ConfigDirPathcharsmax(ConfigDirPath))
    new 
FullPath[256]; formatex(FullPathcharsmax(FullPath), "%s/%s"ConfigDirPathFileName)

    new 
FilePointer fopen(FullPath"rt")
    if(
FilePointer)
    {
        new 
TempFilePath[256]; formatex(TempFilePathcharsmax(TempFilePath), "%s/%s"ConfigDirPathTempFileName)
        
        new 
InputFilePointer fopen(TempFilePath"wt")
        if(
InputFilePointer)
        {
            new 
FileData[128]
            while(!
feof(FilePointer))
            {
                
fgets(FilePointerFileDatacharsmax(FileData))
                
trim(FileData)
                
                if(
equal(FileDataOldLine))
                {
                    continue
                }
                
fprintf(InputFilePointer"%s^n"FileData)
            }
            
            
fclose(InputFilePointer)
            
fclose(FilePointer)

            
delete_file(FullPath)
            
rename_file(TempFilePathFullPath1)
            
            return 
1
        
}
    }
    return 
0

__________________
edon1337 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 12:45.


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