new File:handle = fopen("name.txt", io_read), buf[128]; if(handle) { while(fread(handle, buf)) { if(!strcmp(buf, "GranaT3", true)) { printf("%s", buf); } } } else { print("The file \"file.txt\" does not exists, or can't be opened."); }
while(fread(handle, buf))
{
if(!strcmp(buf, "GranaT3", true))
{
printf("%s", buf);
}
}
You're using "while" incorrectly.
PHP код:
|
public OnGameModeInit()
{
file_a();
return 1;
}
// ** INCLUDES
#include <a_samp>
// ** DEFINES
#define plural_singular(%0,%1,%2) ((%0) == 1) ? ((#%1)) : ((#%2))
// ** MAIN
main()
{
print("Loaded \"count_text_in_file.amx\".");
CountTextInFile("count_text_in_file.txt", "hello");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** FUNCTIONS
stock CountTextInFile(file_name[], text[])
{
new File:file = fopen(file_name, io_read);
if(file)
{
new string[128], count, pos, last_pos, length = strlen(text);
while(fread(file, string))
{
for(;;)
{
pos = strfind(string, text, false, last_pos);
if(pos != -1)
{
last_pos = pos + length;
count ++;
}
else
{
pos = 0;
last_pos = 0;
break;
}
}
}
printf("Found \"%s\" %d %s in \"%s\".", text, count, plural_singular(count, "time", "times"), file_name);
}
else
{
printf("Couldn't open \"%s\".", file_name);
}
return 1;
}
Originally Posted by count_text_in_file.txt
hello how are you
hey hello hey hello bro hello yo yooooo hello hey yo hello bro |
Found "hello" 6 times in "count_text_in_file.txt". |