Quote:
Originally Posted by VEN
string[4] = {0, 'h', 'i', 0} - technically this string is empty because we have nul terminator as the first element of the array.
But at the same time string[4] = {0, 'h', 'i', 0} is the array, but not empty.
If you not sure what to do or didn't get it you can tell me what you trying to achieve so i can tell you what you have to do - check the empty string or the whole array.
Hint: In the most cases for strings you will have to check the empty string (first element).
|
But wait, isn't null \0? It would be different from 0, wouldn't it? Sorry but I'm way too used to writing C, in fact I've never even learned Small, I just code all my AMX scripts as if they were C (for example, all my AMX code have statement-terminating semicolons
). So I was a bit baffled by your some_string[0], since you could assign anything to it, and it doesn't really mean anything...I'm not sure if \0 is null in Small though, so kindly correct me if I'm hopelessly wrong here.
Actually for a function in my plugin, I need to fill up some_string with different strings, separated by commas. If some_string is empty, the function simply fills it up with the first string, if not, then it adds a comma before adding the string. Thus some_string looks like this:
1st time: string1
2nd time: string1,string2
3rd time: string1,string2,string3
......and so on
The function is called several times, as you can see, each time appending a new string, that's why it needs to check if some_string is empty. If it is, then it means it's the first time a string is added to some_string. If it's not then it knows to add a comma before adding another string to it. It seems to be taken care of with
Code:
if (!strlen(some_string))
but I simply want to learn more about this.