[AYUDA]Leer archivo
#1

Bueno estoy haciendo un registro donde se guarden todos los nombres que entran al servidor
con esto guardo en el archivo cada nombre
pawn Код:
forward GuardarEnArchivo(filename[],text[]);
public GuardarEnArchivo(filename[],text[])
{
    new File:archivo, filepath[256], string[256];
    format(filepath,sizeof(filepath),"%s",filename);
    archivo = fopen(filepath,io_append);
    format(string,sizeof(string),"%s\r\n",text);
    fwrite(archivo,string);
    fclose(archivo);
    return 1;
}
Como haria para saber si el nombre esta en el archivo?


NOTA:
Код:
No quiero usar ningun sistema de manejar archivos
Reply
#2

no creo q sea lo mas efectivo pero es lo 1є q se me ocurrio
lee el archivo linea x linea hasta el final
mientras lees cada linea, chequeas si esta el nombre ahi con strfind

tambien podes cargar todo el archivo y chequear si esta o no el nomnre (si haces esto va a ser mejor no usar una linea x nick, si no separarlos x espacios o similar.


las dos son poco eficientes, realmente muy poco eficientes, asi q voy a pensar en otra cosa...
Reply
#3

encontre un ejemplo en la wiki
pawn Код:
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;
}
creo que servira
Reply
#4

https://sampwiki.blast.hk/wiki/File_Functions
https://sampwiki.blast.hk/wiki/Scripting...ons_Old#fmatch
Reply
#5

fmatch es antigua, fue removida

y el ejemplo no sirvio
Reply
#6

Cierren post, fue mas sencillo usar DjSon
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)