Raised This Month: $ Target: $400
 0% 

char_to_num() ?


Post New Thread Reply   
 
Thread Tools Display Modes
stupok
Veteran Member
Join Date: Feb 2006
Old 10-07-2008 , 13:27   Re: char_to_num() ?
Reply With Quote #11

My turn to chime in

string.cpp
Code:
static cell AMX_NATIVE_CALL strtonum(AMX *amx, cell *params) /* 1 param */
{
	int iLen;
	return atoi(get_amxstring(amx, params[1], 0, iLen));
}
src/crt/atoi.c
Code:
/* Copyright (c) Microsoft Corporation. All rights reserved. */
#include <mmlite.h>
#include <stdlib.h>
#include <tchar.h>

/* 7.10.1.2 convert decimal string to int */

int __cdecl _ttoi(const _TCHAR *String)
{
    UINT Value = 0, Digit;
    _TCHAR c;

    while ((c = *String++) != _EOS) {

        if (c >= '0' && c <= '9')
            Digit = (UINT) (c - '0');
        else
            break;

        Value = (Value * 10) + Digit;
    }

    return Value;
}
I love the internets. Also, Lee wins.
stupok is offline
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 10-07-2008 , 14:12   Re: char_to_num() ?
Reply With Quote #12

You cheated! No C++ ! This is Pawn arguments! You lose stupok89!

But yes that would work But who wants to hack that into their own mod, what if it's for a plugin? Native > than you !
Styles is offline
Send a message via AIM to Styles
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 10-07-2008 , 14:30   Re: char_to_num() ?
Reply With Quote #13

Draft, Prajch is exactly right.

It's amusing to watch and participate in these pissing matches.

If you ever want to be a professional software developer, it's a very good habit to convey as much meaning as is possible without hurting elegance. Quantifying elegance is of course no easy task.

The potential employer in me wants Emp`'s code. The part of me who thinks programming is an art and should be something to marvel at - something that grants satisfaction when understood - wants my code. I also feel disdain for people who use high level languages without a thorough understanding of low level concepts. Programming isn't what it used to be and I don't like where it's heading.

Note: I understand that knowledge of ASCII is elementary.

That contributed a lot to the topic.
__________________
No support via PM.

Last edited by Lee; 10-07-2008 at 14:54.
Lee is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-07-2008 , 15:47   Re: char_to_num() ?
Reply With Quote #14

Quote:
Originally Posted by Alka View Post
@Exolent - Little optimization.
PHP Code:
('0' <= temp[0] <= '9'
->
PHP Code:
isdigit(temp[0]) 
heh
Actually, Alka, my version is more optimized because yours uses the native isdigit() whereas mine just compares values.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-07-2008 , 15:59   Re: char_to_num() ?
Reply With Quote #15

Quote:
Originally Posted by styles View Post
You cheated! No C++ ! This is Pawn arguments! You lose stupok89!

But yes that would work But who wants to hack that into their own mod, what if it's for a plugin? Native > than you !
lol... I was just showing you guys the guts of the existing function str_to_num(). It's kinda cool to see what people have written today in Pawn and compare it to what was written ages ago in C.
stupok is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 10-07-2008 , 19:33   Re: char_to_num() ?
Reply With Quote #16

So hard codes for such easy thing, anyway thx all coders
__________________
draft 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 22:58.


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