GetValue(data);
#1

Не могу решить небольшую проблему. Имеется одна функция для считывания данных с массива, что стоят после знака = (взята из gf):

Код:
stock GetValue(line[])
{
	new valRes[128];
	valRes[0] = 0;
	if(strfind(line, "=", true) == -1) return valRes;
	strmid(valRes, line, strfind(line, "=", true) +1, strlen(line), sizeof(valRes));
	return valRes;
}
Мне понадобилось её немного усовершенствовать (может быть в этом и есть моя ошибка):

Код:
stock GetValue(line[], size)
{
	new valRes[size];
	valRes[0] = 0;
	if(strfind(line, "=", true) == -1) return valRes;
	strmid(valRes, line, strfind(line, "=", true) +1, strlen(line), sizeof(valRes));
	return valRes;
}
(то есть добавил параметр size, который указывает размер разбираемого массива)

Вот код для примера, в котором была использована эта функция:

Код:
new test1[128], test2[128], test3[128];
new File:file = fopen("test.cfg", io_read), data[128];
while(fread(file, data, sizeof(data)))
{
	StripNewLine(GetValue(data, sizeof(data)));   // строка 1
 	if(strcmp(GetKey(data), "test1", true) == 0) { test1 = GetValue(data, sizeof(data)); }   // строка 2
	if(strcmp(GetKey(data), "test2", true) == 0) { test2 = GetValue(data, sizeof(data)); }   // строка 3
	if(strcmp(GetKey(data), "test3", true) == 0) { test3 = GetValue(data, sizeof(data)); }   // строка 4
}
fclose(file);
(GetKey(data) тоже взята из gf)

Ну и в результате выходит вот такая ошибка:

Код:
error 035: argument type mismatch (argument 1)   <-   строка 1
error 033: array must be indexed (variable "test1")   <-   строка 2
error 033: array must be indexed (variable "test2")   <-   строка 3
error 033: array must be indexed (variable "test3")   <-   строка 4
Reply


Messages In This Thread
GetValue(data); - by Radius - 15.12.2010, 18:46
Re: GetValue(data); - by Johnny_Xayc - 15.12.2010, 18:58
Re: GetValue(data); - by Radius - 15.12.2010, 19:29
Re: GetValue(data); - by Stepashka - 15.12.2010, 20:04
Re: GetValue(data); - by Radius - 15.12.2010, 21:09
Re: GetValue(data); - by Fro1sha - 16.12.2010, 03:41
Re: GetValue(data); - by Romanius - 16.12.2010, 06:28
Re: GetValue(data); - by Radius - 16.12.2010, 10:12
Re: GetValue(data); - by Maccer - 16.12.2010, 11:49
Re: GetValue(data); - by Radius - 16.12.2010, 15:05

Forum Jump:


Users browsing this thread: 1 Guest(s)