AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reading from a .txt file... (https://forums.alliedmods.net/showthread.php?t=74902)

PvtSmithFSSF 07-26-2008 22:49

Reading from a .txt file...
 
Hey there! New scripter here learning a ton of new things.
What I'm trying to do is create a plugin that displays random messages from a txt file. How do I read lines from a .txt file? I need some1 to please give me some noob-friendly advice if it's possible ;)
Thanks! :up:

Exolent[jNr] 07-26-2008 22:54

Re: Reading from a .txt file...
 
Wrong section. Moved to scripting help.

Code:
new filename[64]; // this is the name of your file to read from copy(filename, 63, "motd.txt"); // lets use motd.txt for the example if( file_exists(filename) ) {     new file = fopen(filename, "rt");         new data[64]; // information taken from the file, 1 line at a time     while( !feof(file) ) // keep looping until we find the end of the file     {         fgets(file, data, 63); // retrieve information         // Note: it will automatically go to the next line                 // data contains the information from the line read     }         // close file     fclose(file); }

Use the funcwiki for information about the natives.

PvtSmithFSSF 07-26-2008 22:57

Re: Reading from a .txt file...
 
thank you very much!
btw i meant to post it here in scripting help :| sorry.


All times are GMT -4. The time now is 05:37.

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