Raised This Month: $ Target: $400
 0% 

IntToString conversion not working?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
343N
Member
Join Date: Jul 2015
Old 02-25-2017 , 21:35   IntToString conversion not working?
Reply With Quote #1

This:

Code:
public int MenuHandler1(Menu menu, MenuAction action, int client, int param2)
{
	/* If an option was selected, tell the client about the item. */
	if (action == MenuAction_Select)
	{
			char newValue[1];
			IntToString((param2 - 1), newValue, 1);
			PrintToChat(client, "Selected Menu Item: %d, conversion to string is %s", (param2 - 1), newValue);
			SetClientCookie(client, VMCookie, newValue);
			OnClientCookiesCached(client);
	}
is printing this:



I can't for the life of me figure out what I'm doing wrong.
343N is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-25-2017 , 21:52   Re: IntToString conversion not working?
Reply With Quote #2

Code:
char newValue[2]; // holds one digit plus string terminator
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-25-2017 , 22:33   Re: IntToString conversion not working?
Reply With Quote #3

Quote:
Originally Posted by nosoop View Post
Code:
char newValue[2]; // holds one digit plus string terminator
It's actually two chars + null terminator...

Last edited by headline; 02-25-2017 at 23:40.
headline is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-26-2017 , 00:13   Re: IntToString conversion not working?
Reply With Quote #4

Quote:
Originally Posted by Headline View Post
It's actually two chars + null terminator...
...no it isn't. The null terminator is considered part of the char array and requires its own entry. I mean, strlen even works by telling you the position in the array of the first null character.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-26-2017 , 00:36   Re: IntToString conversion not working?
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
...no it isn't. The null terminator is considered part of the char array and requires its own entry. I mean, strlen even works by telling you the position in the array of the first null character.
Wait really???

Oh my bad. I definitely though it excluded the null terminator, but now that I think about it it makes sense. Whoops!
headline is offline
343N
Member
Join Date: Jul 2015
Old 02-26-2017 , 03:04   Re: IntToString conversion not working?
Reply With Quote #6

wait, where'd my reply go? I swear I replied to this thread after the first post by nosoop and said thank you.

oh well, thank you nosoop. I'm going to go learn what a string terminator is now. Thanks y'all
343N is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode