Problem with 'fread' function
#1

Hi.
I tried to create an simple script, which need to count some words from some files.
This is the script: http://pastebin.com/m41daf48a
I used the 'print' & 'printf' functions locate the problem.
By the check, the problem was with fread.
It's print the numbers, and after it arrive to 5 - the server get crashed.

Thanks for helpers.
Reply
#2

...
Reply
#3

Here something to solve your crash problem, not the code problem

replace
pawn Код:
f = fopen(allfiles[i],io_read);
with that, it just checks if the file was correctly opened, if not it goes on
pawn Код:
if(!(f = fopen(allfiles[i],io_read))) continue;
and you forgot to use StripNewLine at the first while loop (where you get the filenames)
that was the cause for the incorrect filenames, the result of that was that fopen couldnt open it and fread crash
Reply
#4

OK, I fixed the problem with the file names...
Now this is the script: http://pastebin.com/m60343418
You can tell me please what the problem with lines 40-52?
Reply
#5

mhhh... there is nothing wrong, I just can tell you what happens
if he finds the word "searchs" then
if he finds ")" then
he search for the last ':' after the ')'
at least he just get the text between the ')' and the ':'

the only problem I see if he dont find a ':', dots will be 0 or the number from the search before

the file need to look in some way like that, right ?
Код:
Some stupid Text(searchs)This is what you should get:
and I am not sure if that works
pawn Код:
new stringsToSearch[][12] = {searchs};
i would write it like that, so I know that it is a array
pawn Код:
new stringsToSearch[][] = { "searchs" };
ah and whats with that indentation :S
Reply
#6

Yep, I just tried to get the text between the ')' and the ':'.
I have alot of log files, and I tried to build this system to find how much names do the commands that I defined (searchs).
For example one of the lines in the log:
Код:
[2008/10/1 19:58] (0)Amit_B: /gm 0 10000
The problem must be that he is not find the 'stringsToSearch'.
But from my check... the words is exist.

Anyway, if you find the problem - contact me please
Thanks for the help.

About the indentation - it's just in pastebin.
Reply
#7

Quote:
Originally Posted by Amit B
The problem must be that he is not find the 'stringsToSearch'.
But from my check... the words is exist.
I think that happens because strfind returns 0 for any unknown reason, maybe because it isnt a correct array
and so go on because 0 isnt -1 :S try it with, thats saver I think

pawn Код:
new stringsToSearch[][] = { "/gm" };
and to the other code

pawn Код:
while(fread(f,string,sizeof(string)))
            {
                stripNewLine(string);
                for(new a=0;a<sizeof(stringsToSearch);a++)
                    if(strfind(string,stringsToSearch[a],true) != -1)
                    {
                        closer = strfind(string,")",true);
                        if(closer != -1)
                        {
                            dots = strfind(string,":",true,closer+1);
                            strmid(pname,string,closer+1,dots-1);
                        }
                    }
            }
But I see now, if you have as example
Код:
[2008/10/1 19:58] (0)Amit_B: /gm 0 10000
[2008/10/1 19:58] (0)Nero: /gm 0 10000
[2008/10/1 19:58] (0)Josef: /gm 0 10000
pname would always be overwriten, first it would be Amit_B but the end result will be Josef
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)