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

Solved Add character in existing line


Post New Thread Reply   
 
Thread Tools Display Modes
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-14-2018 , 07:27   Re: Add character in existing line
Reply With Quote #11

I think I wanted to make a stock to change a line, but then I made it to delete a line and that's why NewLine is not used.
__________________
HamletEagle is online now
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-14-2018 , 07:36   Re: Add character in existing line
Reply With Quote #12

Quote:
Originally Posted by HamletEagle View Post
I think I wanted to make a stock to change a line, but then I made it to delete a line and that's why NewLine is not used.
How do I make it delete and replace?
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-14-2018 , 07:39   Re: Add character in existing line
Reply With Quote #13

Re-read this: https://forums.alliedmods.net/showpo...41&postcount=2
__________________
HamletEagle is online now
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-14-2018 , 07:51   Re: Add character in existing line
Reply With Quote #14

Quote:
Originally Posted by HamletEagle View Post
Like this?
PHP Code:
public Function( )
{
    new 
szOldString128 ], szNewString128 ];
    
formatexszOldStringcharsmaxszOldString ), "%s %s %s %s"szNameszPasswordszFlagsszPrefix );
    
formatexszOldStringcharsmaxszOldString ), ";%s %s %s %s"szNameszPasswordszFlagsszPrefix );
    
    
ReplaceLineszFormatszOldStringszNewString );
}

ReplaceLine(const FileName[], const OldLine[], const szNewLine[])
{
    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))
                {
                    
fprintf(InputFilePointer"%s^n"szNewLine)
                }
                
                else
                
fprintf(InputFilePointer"%s^n"FileData)
            }
            
            
fclose(InputFilePointer)
            
fclose(FilePointer)

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

__________________

Last edited by edon1337; 08-14-2018 at 07:51.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-14-2018 , 07:58   Re: Add character in existing line
Reply With Quote #15

Looks fine, try it.
__________________
HamletEagle is online now
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-14-2018 , 08:38   Re: Add character in existing line
Reply With Quote #16

Well, that didn't work, but I managed to fix it, thanks!
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-14-2018 , 09:51   Re: Add character in existing line
Reply With Quote #17

You should be posting the final code, may help others.
__________________
HamletEagle is online now
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 06:40.


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