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

C file natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FatalisDK
Senior Member
Join Date: Mar 2006
Location: bacon
Old 10-22-2006 , 19:41   C file natives
Reply With Quote #1

I want to convert this to the C file natives (fopen, fseek, fgets, etc)
And yes, I know this plugin doesnt handle any errors, it's just a rough draft.

Code:
#include <amxmodx> #define PLUGIN "New Plugin" #define VERSION "0.1" #define AUTHOR "FatalisDK" new const gFILE[] = "test.txt"; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     test(); } test() {     //Display last 10 lines of file - File is always greater than 10 lines     //How would I do this using the C file natives? (or whatever you call them)         new lines = file_size(gFILE, 1);     new szData[3], txtLen         for( new i = lines-10; i < lines; i++ )     {                 read_file(gFILE, i, szData, 2, txtLen);         server_print("%i = %s", i, szData);     } }
__________________
FatalisDK is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-22-2006 , 21:21   Re: C file natives
Reply With Quote #2

The code I gave you was fine; the only problem with it was I don't know how to go back 10 lines lol.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 10-23-2006 , 05:11   Re: C file natives
Reply With Quote #3

This works, but it's not very efficient. I won't recommend you to use it.
If I only knew how to tell the filePointer to move a line further without using fgets().

Code:
#include <amxmodx> #include <amxmisc> #pragma semicolon 1 new g_file[64]; public plugin_init() {     register_plugin("File Natives Test", "x", "MaximusBrood");         get_configsdir(g_file, 63);     format(g_file, 63, "%s/test.txt", g_file);         register_srvcmd("testMe", "readFile"); } public readFile() {     //Note that this is very ugly     //I don't really know how to use fseek()     if(!file_exists(g_file))         return;             //Open file     new filePointer = fopen(g_file, "rt");     if(!filePointer)         return;             //Get the text     new targetLine = file_size(g_file, 1) - 10;         static buffer[128]; new b = 0;     for(new a = 0; !feof(filePointer) && b <= 10; a++)     {         fgets(filePointer, buffer, 127);                 if(a < targetLine)             continue;                 server_print("%d = %s", b, buffer);                 b++;     } }
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood 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 11:00.


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