AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   reading line ( linux & windows line format ) (https://forums.alliedmods.net/showthread.php?t=248691)

.Dare Devil. 09-21-2014 23:37

reading line ( linux & windows line format )
 
Hello everyone!

here's my code:
PHP Code:

    new fopen(file"rt")
    while (
&& !feof(f))
    {
        
fgets(ftemp21023)
        
replace(temp21023"^n""")
    } 

The thing is that it will fail if i load window line format files on linux...
what do i mean by linux&window line format:

window's one:
[IMG]http://s29.************/8wigyi987/window.png[/IMG]
line: 13 10 or 0D0A ( 2 bytes )

linux's one:
[IMG]http://s13.************/f4nkzitjr/linux.png[/IMG]
line: 10 or 0A ( 1 byte )

for example loading windows lines in linux will cause fgets to get whole file, i assume that because
while i was debugging the code, loop did only one cycle.
I dont know how windows will react to linux lines, never tried it. Didn't find it that important i guess...
Anyideas how to fix my problem here?

Thanks!


edit:
one solution would be using fread i guess.
Calling fread for every char but this is just too bad, i better code module and parse things there but i was hoping there's another way.

Arkshine 09-22-2014 04:05

Re: reading line ( linux & windows line format )
 
I don't understand what is your problem (all your said doesn't make much sense for me), but you should use "trim()" and not this silly "replace(temp2, 1023, "^n", "")".

hzqst 09-22-2014 08:31

Re: reading line ( linux & windows line format )
 
why not refer the AMXX source code?

.Dare Devil. 09-22-2014 14:13

Re: reading line ( linux & windows line format )
 
Quote:

Originally Posted by Arkshine (Post 2202267)
I don't understand what is your problem (all your said doesn't make much sense for me), but you should use "trim()" and not this silly "replace(temp2, 1023, "^n", "")".

Even removing replace func wont help it.
You really never had this kind of problem?
Also, can you point out of parts which confused you, i try to make things cleared.

Arkshine 09-22-2014 15:24

Re: reading line ( linux & windows line format )
 
Are you saying fgets fails to find \n under linux, if text file has \r\n as line end? This doesn't make much sense for me.

fysiks 09-22-2014 15:59

Re: reading line ( linux & windows line format )
 
Quote:

Originally Posted by .Dare Devil. (Post 2202219)
for example loading windows lines in linux will cause fgets to get whole file, i assume that because
while i was debugging the code, loop did only one cycle.

You must be doing something else wrong because there is no issue with reading Windows-terminated lines in Linux (I develop everything on Windows and run it on Linux). I just tested it also.

Maybe you should post more stuff. Attach your text file that is causing this behavior as well as your test plugin in which you've been able to reproduce the error.

.Dare Devil. 09-23-2014 09:14

Re: reading line ( linux & windows line format )
 
Quote:

Originally Posted by Arkshine (Post 2202477)
Are you saying fgets fails to find \n under linux, if text file has \r\n as line end? This doesn't make much sense for me.

It didin't make any sense for me to until i tried and changed the file lines.
Then it was fine.


All times are GMT -4. The time now is 01:20.

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