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

reading line ( linux & windows line format )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-21-2014 , 23:37   reading line ( linux & windows line format )
Reply With Quote #1

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.

Last edited by .Dare Devil.; 09-21-2014 at 23:40.
.Dare Devil. is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-22-2014 , 04:05   Re: reading line ( linux & windows line format )
Reply With Quote #2

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", "")".
__________________
Arkshine is offline
hzqst
Senior Member
Join Date: Jul 2008
Old 09-22-2014 , 08:31   Re: reading line ( linux & windows line format )
Reply With Quote #3

why not refer the AMXX source code?
hzqst is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-22-2014 , 14:13   Re: reading line ( linux & windows line format )
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
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.
.Dare Devil. is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-22-2014 , 15:24   Re: reading line ( linux & windows line format )
Reply With Quote #5

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

Last edited by Arkshine; 09-22-2014 at 15:24.
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-22-2014 , 15:59   Re: reading line ( linux & windows line format )
Reply With Quote #6

Quote:
Originally Posted by .Dare Devil. View Post
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.
__________________

Last edited by fysiks; 09-22-2014 at 16:15.
fysiks is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-23-2014 , 09:14   Re: reading line ( linux & windows line format )
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
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.
.Dare Devil. 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:22.


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