22.01.2011, 12:22
Yes you need a loop, just check in it if the name already got added
If it doesnt add the new name to a free space, done
The code below is just an example
If it doesnt add the new name to a free space, done
The code below is just an example
pawn Код:
stock AddToData(data[][], input[], i = sizeof data, const size = sizeof data[])
{
if(!input[0]) return 0; //checks if the input is emtpy
new free = -1; //declares free as -1
while((--i) != -1) //A while loop
if(!data[i][0]) free = i; //Checks if the data space is emtpy - necessary because of strcmp
else if(!strcmp(input, data[i], true)) return 0; //Checks if the name is the same
if(free == -1) return -1; //returns -1 if no free space was found
strcat(data[free], input, size); //insert the input in the free data space
return 1; //returns 1 for success
}