Raised This Month: $ Target: $400
 0% 

Text formating?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 01-08-2006 , 20:43   Text formating?
Reply With Quote #1

I was looking through amxmodx.inc and saw this:
Code:
/* Prints message to server console.
* You may use text formating (f.e. server_print("%-32s %.2f!","hello",7.345)) */
???
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 01-08-2006 , 20:44  
Reply With Quote #2

This link should help.
http://www.cplusplus.com/ref/cstdio/printf.html
Brad is offline
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 01-08-2006 , 20:47  
Reply With Quote #3

Thanks for the fast help !
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 01-08-2006 , 20:50  
Reply With Quote #4

No problem, I had some time while I'm waiting for Mein to come over.
Brad is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 01-08-2006 , 21:52  
Reply With Quote #5

Har har.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 01-09-2006 , 10:06  
Reply With Quote #6

Also, what else can you format?
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 01-09-2006 , 10:49  
Reply With Quote #7

What do you mean, "what else"? What else are you referring to?
Brad is offline
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 01-09-2006 , 10:51  
Reply With Quote #8

What else can you use text formating?
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 01-09-2006 , 11:26  
Reply With Quote #9

Anywhere you can use %s, %i, and the like. format(), client_print(), etc.
Brad is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 01-09-2006 , 12:16  
Reply With Quote #10

Which makes it DANGEROUS to pass strings which were supplied from outside to such a function directly.

Imagine this example:

Code:
// Assume this is in a client command handler new text[32]; read_argv(1, text, 31); client_print(id, print_chat, text);   //!!!!

It may look right, but when the client types:
command "hello %s", you will get a native error and he won't get any message. It's not as damaging in small as it is in C/C++, where your program usually crashes on such occassions (like valve's source bug where you would crash all clients if your name contained %s and you made your name appear in the hud, eg. by commiting suicide).

It's better to do this:
Code:
client_print(id, print_chat, "%s", text);
__________________
hello, i am pm
PM is offline
Reply


Thread Tools
Display Modes

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 16:13.


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