Raised This Month: $ Target: $400
 0% 

Read/writeing in files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stigma
Senior Member
Join Date: Mar 2005
Location: Denmark
Old 10-14-2006 , 22:15   Read/writeing in files
Reply With Quote #1

If i have a file called gNames.txt and to search the entire file, for an steamID, what would i do then?

And if i have a line saying: "stigma B 21", then what should i do if i want my plugin to read the second word, which is equal to "B"?
stigma is offline
Send a message via MSN to stigma Send a message via Skype™ to stigma
stupok
Veteran Member
Join Date: Feb 2006
Old 10-15-2006 , 00:10   Re: Read/writeing in files
Reply With Quote #2

Search the entire file for a steamid:
Code Snippet:
Code:
new pAuth[33], Len, Text[101], File[32]         get_user_authid(id, pAuth, 32)         if(is_user_bot(id))                 return PLUGIN_CONTINUE         new lines = file_size(szFile, 1)         for(new i=0; i<lines; i++) {                 read_file(File, i, Text, 100, Len)                 if(equali(Text, pAuth)) {                         //code...                 }         }

To read the second word:
Code snippet:
Code:
new File[33], Text[101], something[5], Bthing[33], somethingelse[33], Len, i read_file(File, i, Text, 100, Len) parse(Text, something, 4, Bthing, 32, somethingelse, 32) //the value B from "stigma B 21" would be held in the array called Bthing

Or, just look at my plugin called Users List.
stupok is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 10-15-2006 , 08:13   Re: Read/writeing in files
Reply With Quote #3

Another way are the new filehandle commands
Code:
new authid[32],steamid[32],array[32] get_user_authid(id,authid,31) new fp=fopen("gNames.txt","rw")//open file in read-write mode while(!feof(fp)) //read lines until end-of-file {     fgets (fp,array,31)//read a line from file     parse(array,steamid,31)     if(equali(steamid,authid))//check if steamid(in file) is same as authid from player     {         client_print(0,print_chat,"steamid==authid:%s",authid,steamid)         //your code here...     } }
__________________

Last edited by schnitzelmaker; 10-15-2006 at 08:18.
schnitzelmaker is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 10-15-2006 , 08:52   Re: Read/writeing in files
Reply With Quote #4

search for authid:
Code:
search_file_for_auth(file[] = "addons/amxmodx/...", match_auth[]) {     new line, text[64], len         while ( read_file(file, line++, text, 63, len) ) {                 if ( contain(text, match_auth) != -1 )             return 1 // match     }     return 0 // no match }

Code:
new line, text[64], second_word[2], len, file[] = "addons/amxmodx/..." while ( read_file(file, line++, text, 63, len) ) {         strbreak(text, text, 0, second_word, 1) }

parse() is bad

Last edited by [ --<-@ ] Black Rose; 10-15-2006 at 09:36.
[ --<-@ ] Black Rose is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-15-2006 , 10:52   Re: Read/writeing in files
Reply With Quote #5

You should know better than to hardcode paths

get_localinfo();
get_configsdir();
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 10-15-2006 , 11:29   Re: Read/writeing in files
Reply With Quote #6

Quote:
parse() is bad
Not true:"strbreak" only support 2 words,where you know the lenght of the words,it dont support spaces,tabs,newlines,...

"strbreak" is not constructed for filehandle.It is for like "replace",search a string inside and break them into 2 strings.
__________________

Last edited by schnitzelmaker; 10-15-2006 at 11:33.
schnitzelmaker is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-15-2006 , 11:32   Re: Read/writeing in files
Reply With Quote #7

Just because I native has a good purpose/use doesn't mean the implementation of it is. I'm not saying it is bad, just bringing up a point.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 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 04:50.


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