Fread
From SA-MP Wiki
Read from a file.
(File:handle, string[], size = sizeof string, bool: pack = false)
| handle | The file to read from |
| string | The string to store the read text in, passed by reference |
| size | The number of bytes to read |
| pack | Should the string reference be packed? |
| Returns | The length of string (the read text) as an integer. |
public OnGameModeInit() { new string[64]; // Create the string to store the read text in new File:example = fopen("Startup.txt", io_read); // Open the file fread(example, string); // Fread from the file and store what's read in 'string' fclose(example); // Close the file printf("%s",string); // Print what was read return 1; }
Reading Line-by-Line
public OnPlayerConnect(playerid) { new string[64]; // Create the string to store the read text in new File:example = fopen("Startup.txt", io_read); // Open the file while(fread(example, string)) //reads the file line-by-line { if(strcmp(string, "Ban", true) == 0) //if any of the lines in the file say "Ban" the system will ban the player { Ban(playerid); //bans the player } } fclose(example); return 1; }
Related Functions
The following functions may be useful, as they are related to this function in one way or another.
- fwrite: Write to a file.
- fopen: Open a file.
- fclose: Close a file.
- fremove: Remove a file.
