12.04.2013, 17:46
Hello, I'm getting a tag mismatch with this:
I have looked on the wiki and it seems to be the correct syntax..
pawn Код:
while( fread(filehandle, line) )
while( fread(filehandle, line) )
new line[128]; //A string a 128 string cell (depending on the size of your file, change it)
new File:filehandle = fopen("" /* << .txt file location/name */, io_read); // this will open the file
while(fread(filehandle, line)) // This will read the file
{
// Your code here
}
fclose(filehandle); // Closes the file
stock INI_GetInt(filehandle, Key[], &dest) {
new pos, line[MAX_FILE_STRING];
while( fread(filehandle, line) ) {
if( (pos = strfind(line, Key, false)) != -1 ) {//-1 would be not found
new idx = pos + strlen(Key) + 1;
if(line[idx] == ' ') {//the value is nothing
idx = pos + strlen(Key) + 2;//if the = sign is further across
if(idx > strlen(line)) return -1; //there was no value found
dest = (idx < sizeof(line)) ? strval(line[idx]) : 0;
return 1;
}
dest = (idx < sizeof(line)) ? strval(line[idx]) : 0;
return 1;
}
}
return 0;
}
new File:Myfile = fopen("MyFile.ini", io_read), myscore;
INI_GetInt(Myfile, "score", myscore);
fclose(Myfile);
stock INI_GetInt(File:filehandle, Key[], &dest) { new pos, line[MAX_FILE_STRING]; while( fread(filehandle, line) ) { if( (pos = strfind(line, Key, false)) != -1 ) {//-1 would be not find new idx = pos + strlen(Key) + 1; if(line[idx] == ' ') {//the value is nothing idx = pos + strlen(Key) + 2;//if the = sign is further across if(idx > strlen(line)) return -1; //there was no value found dest = (idx < sizeof(line)) ? strval(line[idx]) : 0; return 1; } dest = (idx < sizeof(line)) ? strval(line[idx]) : 0; return 1; } } return 0; }