AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved new line char (https://forums.alliedmods.net/showthread.php?t=299562)

KiLLeR. 07-18-2017 12:29

new line char
 
Is the '^n' char equal for all operating systems in amxx?

File:
Code:

line1
line2
line3

line4
line5

Code:
Code:
new f = fopen(blc_file, "rt");         if(f)     {         new text[32];         server_print("** Reading file:");         while(!feof(f))         {             fgets(f, text, charsmax(text));                         if(!text[0] || text[0] == ';' || text[0] == '^n')                 continue;                         server_print(text);         }                 fclose(f);     }
Output:
Code:

** Reading file:
line1

line2

line3

line4

line5

I want to remove empty lines?!?!

klippy 07-18-2017 12:38

Re: new line char
 
Use trim().

PRoSToTeM@ 07-18-2017 14:31

Re: new line char
 
Quote:

Originally Posted by KiLLeR. (Post 2536146)
Is the '^n' char equal for all operating systems in amxx?

Yes, if you open file in text mode.

KiLLeR. 07-20-2017 07:02

Re: new line char
 
Quote:

Originally Posted by KliPPy (Post 2536150)
Use trim().

Thanks you, I forgot about this.
Code:
if(equal(text, "line1") // why this returns true if text contains actually a "line^n"

DarthMan 07-20-2017 08:14

Re: new line char
 
Quote:

Originally Posted by KiLLeR. (Post 2536538)
Thanks you, I forgot about this.
Code:
if(equal(text, "line1") // why this returns true if text contains actually a "line^n"

You could also use if (text[0] == EOS ...) .
EOS is for new line(empty).

edon1337 07-20-2017 09:18

Re: new line char
 
Quote:

Originally Posted by DarthMan (Post 2536544)
You could also use if (text[0] == EOS ...) .
EOS is for new line(empty).

Or simply
Code:
if( ! text[ 0 ] )

KiLLeR. 07-21-2017 15:35

Re: new line char
 
Your reply have no sense with my question?!?!
Maybe let's explain better...
fgets read the entire line plus line terminator, so what actually I have in string text is "line1^n" and when I'm comparing the string in text ("line^n") with manually writen string "line1", it returns true?!?!

fysiks 07-22-2017 00:39

Re: new line char
 
PHP Code:

#include <amxmodx>

public plugin_init()
{
   
register_srvcmd("compare""cmdCompare")
}

public 
cmdCompare()
{
    new 
szLine1[] = "hello^n"
    
new szLine2[] = "hello"
    
    
server_print("equal(^"%s^",^"%s^") -> %s"szLine1szLine2equal(szLine1szLine2) ? "True" "False")
    
server_print("equal(^"%s^",^"%s^") -> %s"szLine2szLine1equal(szLine2szLine1) ? "True" "False")


:arrow:
Code:

compare
equal("hello
","hello") -> False
equal("hello","hello
") -> False

Therefore, what you claim is not actually happening since it actually returns false based on this plugin.


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

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