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

Solved new line char


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 07-18-2017 , 12:29   new line char
Reply With Quote #1

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?!?!

Last edited by KiLLeR.; 08-27-2017 at 15:22.
KiLLeR. is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-18-2017 , 12:38   Re: new line char
Reply With Quote #2

Use trim().
klippy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-18-2017 , 14:31   Re: new line char
Reply With Quote #3

Quote:
Originally Posted by KiLLeR. View Post
Is the '^n' char equal for all operating systems in amxx?
Yes, if you open file in text mode.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 07-20-2017 , 07:02   Re: new line char
Reply With Quote #4

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

Last edited by KiLLeR.; 07-20-2017 at 07:04.
KiLLeR. is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-20-2017 , 08:14   Re: new line char
Reply With Quote #5

Quote:
Originally Posted by KiLLeR. View Post
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).
DarthMan is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-20-2017 , 09:18   Re: new line char
Reply With Quote #6

Quote:
Originally Posted by DarthMan View Post
You could also use if (text[0] == EOS ...) .
EOS is for new line(empty).
Or simply
Code:
if( ! text[ 0 ] )
__________________
edon1337 is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 07-21-2017 , 15:35   Re: new line char
Reply With Quote #7

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?!?!

Last edited by KiLLeR.; 07-21-2017 at 15:39.
KiLLeR. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-22-2017 , 00:39   Re: new line char
Reply With Quote #8

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")


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.
__________________

Last edited by fysiks; 07-22-2017 at 00:43.
fysiks 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 00:02.


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