Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - IMPLEMENTAZIONE LIBRERIA
Forum - C/C++ - IMPLEMENTAZIONE LIBRERIA

Avatar
hck8 (Normal User)
Newbie


Messaggi: 2
Iscritto: 23/11/2012

Segnala al moderatore
Postato alle 16:56
Venerdì, 23/11/2012
Questo topic è stato chiuso dal moderatore

salve a tutti sono nuovo e chiedevo il vostro aiuto su come posso aggiungere questa libreria nel mio programma c++ premetto che la lib. nn l'ho scritta io ma è "dini.inc" (se qualcuno ha lavorato su samp server la conosce di sicuro)
ecco il mio problema quando sotto il mio #include <iostrem> inserisco #include <percorso\dini.inc> mi si apre un file dove mi da errore sullo stock per favore aiutatemi
ecco il codice di "dini.inc"
/*
*            Dini 1.6
*       (c) Copyright 2006-2008 by DracoBlue
*
* @author    : DracoBlue (http://dracoblue.com)
* @date      : 13th May 2006
* @update    : 16th Sep 2008
*
* This file is provided as is (no warranties).
*
* It's released under the terms of MIT.
*
* Feel free to use it, a little message in
* about box is honouring thing, isn't it?
*
*/

#if defined _dini_included
  #endinput
#endif

#define _dini_included
#pragma library dini

#if defined MAX_STRING
#define DINI_MAX_STRING MAX_STRING
#else
#define DINI_MAX_STRING 255
#endif

stock dini_Exists(filename[]) {
    return fexist(filename);
}

stock dini_Remove(filename[]) {
    return fremove(filename);
}

stock dini_Create(filename[]) {
    if (fexist(filename)) return false;
    new File:fhnd;
    fhnd=fopen(filename,io_write);
    if (fhnd) {
        fclose(fhnd);
        return true;
    }
    return false;
}

stock dini_Set(filename[],key[],value[]) {
    // If we have no key, it can't be set
    // we also have no chance to set the value, if all together is bigger then the max string
    new key_length = strlen(key);
    new value_length = strlen(value);
    if (key_length==0 || key_length+value_length+2>DINI_MAX_STRING) return false;
    
    new File:fohnd, File:fwhnd;
    new tmpres[DINI_MAX_STRING];
    new bool:wasset=false;
    
    // Let's remove the old *.part file if there was one.
    format(tmpres,sizeof(tmpres),"%s.part",filename);
    fremove(tmpres);
    
    // We'll open the source file.
    fohnd=fopen(filename,io_read);
    if (!fohnd) return false;
    
    fwhnd=fopen(tmpres,io_write);
    if (!fwhnd) {
        // we can't open the second file for writing, so .. let's close the open one and exit.
        fclose(fohnd);
        return false;
    }
    
    while (fread(fohnd,tmpres)) {
        if (
            !wasset
            && tmpres[key_length]=='='
            && !strcmp(tmpres, key, true, key_length)    
        ;) {
                // We've got what needs to be replaced!
                format(tmpres,sizeof(tmpres),"%s=%s",key,value);
                wasset=true;
        } else {
            DINI_StripNewLine(tmpres);
        }
        fwrite(fwhnd,tmpres);
        fwrite(fwhnd,"\r\n");
    }

    if (!wasset) {
        format(tmpres,sizeof(tmpres),"%s=%s",key,value);
        fwrite(fwhnd,tmpres);
        fwrite(fwhnd,"\r\n");
    }

    fclose(fohnd);
    fclose(fwhnd);

    format(tmpres,sizeof(tmpres),"%s.part",filename);
    if (DINI_fcopytextfile(tmpres,filename)) {
        return fremove(tmpres);
    }
    return false;
}


stock dini_IntSet(filename[],key[],value) {
   new valuestring[DINI_MAX_STRING];
   format(valuestring,DINI_MAX_STRING,"%d",value);
   return dini_Set(filename,key,valuestring);
}

stock dini_Int(filename[],key[]) {
   return strval(dini_Get(filename,key));
}

stock dini_FloatSet(filename[],key[],Float:value) {
   new valuestring[DINI_MAX_STRING];
   format(valuestring,DINI_MAX_STRING,"%f",value);
   return dini_Set(filename,key,valuestring);
}

stock Float:dini_Float(filename[],key[]) {
   return floatstr(dini_Get(filename,key));
}

stock dini_Bool(filename[],key[]) {
   return strval(dini_Get(filename,key));
}

stock dini_BoolSet(filename[],key[],value) {
    if (value) {
        return dini_Set(filename,key,"1");
    }
    return dini_Set(filename,key,"0");
}

stock dini_Unset(filename[],key[]) {
    // If we have no key, it can't be set
    // we also have no chance to unset the key, if all together is bigger then the max string
    new key_length = strlen(key);
    if (key_length==0 || key_length+2>DINI_MAX_STRING) return false;
    
    new File:fohnd, File:fwhnd;
    new tmpres[DINI_MAX_STRING];
    
    // Let's remove the old *.part file if there was one.
    format(tmpres,DINI_MAX_STRING,"%s.part",filename);
    fremove(tmpres);
    
    // We'll open the source file.
    fohnd=fopen(filename,io_read);
    if (!fohnd) return false;
    
    fwhnd=fopen(tmpres,io_write);
    if (!fwhnd) {
        // we can't open the second file for writing, so .. let's close the open one and exit.
        fclose(fohnd);
        return false;
    }
    
    while (fread(fohnd,tmpres)) {
        if (
            tmpres[key_length]=='='
            && !strcmp(tmpres, key, true, key_length)    
        ;) {
                // We've got what needs to be removed!
        } else {
            DINI_StripNewLine(tmpres);
            fwrite(fwhnd,tmpres);
            fwrite(fwhnd,"\r\n");
        }
    }
    
    fclose(fohnd);
    fclose(fwhnd);

    format(tmpres,DINI_MAX_STRING,"%s.part",filename);
    if (DINI_fcopytextfile(tmpres,filename)) {
        return fremove(tmpres);
    }
    return false;
}

stock dini_Get(filename[],key[]) {
    new tmpres[DINI_MAX_STRING];
    
    new key_length = strlen(key);
    if (key_length==0 || key_length+2>DINI_MAX_STRING) return tmpres;
    
    new File:fohnd;
    fohnd=fopen(filename,io_read);
    if (!fohnd) return tmpres;
    
    while (fread(fohnd,tmpres)) {
        if (
            tmpres[key_length]=='='
            && !strcmp(tmpres, key, true, key_length)    
        ;) {
            /* We've got what we need */
            DINI_StripNewLine(tmpres);
            strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), DINI_MAX_STRING);
            fclose(fohnd);
            return tmpres;
        }
    }
    fclose(fohnd);
    return tmpres;
}


stock dini_Isset(filename[],key[]) {
    new key_length = strlen(key);
    if (key_length==0 || key_length+2>DINI_MAX_STRING) return false;
    
    new File:fohnd;
    fohnd=fopen(filename,io_read);
    if (!fohnd) return false;
    
    new tmpres[DINI_MAX_STRING];
    while (fread(fohnd,tmpres)) {
        if (
                tmpres[key_length]=='='
            &&  !strcmp(tmpres, key, true, key_length)    
        ;) {
            // We've got what we need
            fclose(fohnd);
            return true;
        }
    }
    fclose(fohnd);
    return false;
}



stock DINI_StripNewLine(string[]) {
    new len = strlen(string);
    if (string[0]==0) return ;
    if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
        string[len - 1] = 0;
        if (string[0]==0) return ;
        if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
    }
}

stock DINI_fcopytextfile(oldname[],newname[]) {
    new File:ohnd,File:nhnd;
    if (!fexist(oldname)) return false;
    ohnd=fopen(oldname,io_read);
    if (!ohnd) return false;
    nhnd=fopen(newname,io_write);
    if (!nhnd) {
        fclose(ohnd);
        return false;
    }
    new tmpres[DINI_MAX_STRING];
    while (fread(ohnd,tmpres)) {
        DINI_StripNewLine(tmpres);
        format(tmpres,sizeof(tmpres),"%s\r\n",tmpres);
        fwrite(nhnd,tmpres);
    }
    fclose(ohnd);
    fclose(nhnd);
    return true;

PM
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6380
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 17:08
Venerdì, 23/11/2012
Non devi includere il codice con una #include, non è un file include ma un file sorgente .cpp

Va aggiunto al tuo progetto e compilato insieme agli altri (se usi un IDE lo devi aggiungere al progetto).

E' difficile dirti se ci saranno altri errori e come rimediare perché non si sa

1) cosa usi per compilare

2) non si sa per quale piattaforma è nato quel sorgente

3) non si sa se dipende da altri file (include, sorgenti)


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti (uno dei padri fondatori del moderno Calcolo delle probabilità) chiamava il gioco del Lotto Tassa sulla stupidità.
PM
Avatar
HeDo (Founder Member)
Guru^2


Messaggi: 2765
Iscritto: 21/09/2007

Segnala al moderatore
Postato alle 1:18
Sabato, 24/11/2012
Questo topic è in violazione di una o più norme del regolamento: http://www.pierotofy.it/pages/extras/forum/9/3839-regolame ... .
    
Dopo averlo letto riapri un nuovo topic assicurandoti di aver rispettato le regole. Grazie per la tua pazienza.

PM