Filling a String
#1

Hey all!

I want to create a dialog, where I'll put a lot of informations, and after every 10th information start the next in a new line. I created a for cycle, which fills up the string with the infos, so now I just need a function that returns true, if 'variable/10 == integer' and returns false, if it's float.

How to do it?

Thanks
Nonameman
Reply
#2

Heres a example.

Код:
new string[128];
format(string,sizeof string,"Something");
format(string,sizeof string,"%s\nLine 2",string);
If im not mistaken thats what you want...

The final string will be:

Код:
Something
Line2
Reply
#3

I know how to make a new line, what I want is a function, the integer/float checker
Reply
#4

Try this, its untested but I see no reason for it not to work:

pawn Код:
stock IsDivTen(val)
{
    return (val % 10)?(false):(true);
}
Reply
#5

Thanks, can You show me how is it works
Код:
return (val % 10)?(false):(true);
, because I've never seen someting like this
Reply
#6

The % operator is called the modulus operator (nothing like the mathematical modulus like |-5| = 5).

It will return the remainder of a division, so if you do:
pawn Код:
20 % 10
It will return 0, because 20 goes into 10 twice, with 0 remainder.

However if you do:
pawn Код:
21 % 10
It will return 1, because 21 can be divided into 10 twice (the 20) and then theres 1 remainder.

The ? and : are triadic operators, so the whole function is basically saying:

"If the return value of 'val % 10' is 0, then return true, if there is any remainder, then return false."

So if you plug a value into that function it will return true if the value is divisible by 10, and return false if its not.

You could also use a macro:

pawn Код:
#define IsDivTen(%1) ((%1) % 10)?(false):(true)
Reply
#7

Thanks a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)