Almacenar color hex en variable
#3

Como un integer o un string, no importa.

pawn Код:
// ** INCLUDES

#include <a_samp>
#include <sscanf>

// ** DEFINES

// *** GENERAL

#define HEX_VALUE "0xFFFFFFFF"
#define INTEGER_VALUE -1

// *** FUNCTIONS

#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

// ** MAIN

main()
{
    print("Loaded \"color_hex_int.amx\"");

    printf(""#HEX_VALUE" to integer: %i", HexToInt(HEX_VALUE));
    printf(""#INTEGER_VALUE" to hexadecimal: %s", IntToHex(INTEGER_VALUE));

    new string[11], answer[12];
    strcpy(string, HEX_VALUE, 11);
    answer = (IsHexOrInt(string)) ? ("Hexadecimal") : ("Integer");
    printf("Is %s an integer or a hexadecimal value? %s", string, answer);

    format(string, sizeof(string), "%d", INTEGER_VALUE);
    answer = (IsHexOrInt(string)) ? ("Hexadecimal") : ("Integer");
    printf("Is %s an integer or a hexadecimal value? %s", string, answer);
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// ** FUNCTIONS

stock HexToInt(hex[])
{
    new int;
    sscanf(hex, "x", int);
    return int;
}

stock IntToHex(int)
{
    new string[7];
    format(string, sizeof(string), "%06x", int >>> 8);
    return string;
}

stock IsNumeric(const string[])
{
    return !sscanf(string, "{d}");
}

stock IsHexOrInt(hex[])
{
    if(IsNumeric(hex)) return false;
    return true;
}
Reply


Messages In This Thread
Almacenar color hex en variable - by Ghost112397 - 28.12.2015, 14:26
Respuesta: Almacenar color hex en variable - by FelipeAndres - 28.12.2015, 15:04
Re: Almacenar color hex en variable - by SickAttack - 28.12.2015, 16:07

Forum Jump:


Users browsing this thread: 1 Guest(s)