strmid has a bug
#1

pawn Код:
new DEBUG[10],ABC[3],DEF[3];
format(DEBUG,10,"ABCDEF");
strmid(ABC,DEBUG,0,2);
strmid(DEF,DEBUG,3,5);
printf("Should be ABC: '%s'\nShould be DEF: '%s'",ABC,DEF);
Output is:

Код:
Should be ABC: 'AB'
Should be DEF: 'DE'
Any solutions to this? It worked fine the first time i tested it, but after a server restart it got like this...
Reply
#2

You are not including the space required for the null terminator, which results in stack overflow. The arrays "ABC" and "DEF" should each be 4 cells wide to hold a string of length 3 + null terminator.

On another note, don't write variable names in all caps. By convention, all caps is reserved for constants (#define and const).
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
You are not including the space required for the null terminator, which results in stack overflow. The arrays "ABC" and "DEF" should each be 4 cells wide to hold a string of length 3 + null terminator.

On another note, don't write variable names in all caps. By convention, all caps is reserved for constants (#define and const).
I know all that, i just threw this together and put it inside main() to see whether it was interfered by whatever I'm doing. Yeah, forgot about the null char, but the array size doesn't matter, the result remains the same.... (just tested)
Reply
#4

I got it working, got help via PM. I never thought about including the null char in the strmid 'end' :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)