C++ (Cpp) sscanf Examples

C++ (Cpp) sscanf - 30 examples found. These are the top rated real world C++ (Cpp) examples of sscanf extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
bool
Reader::decodeDouble( Token &token )
{
    double value = 0;
    const int bufferSize = 32;
    int count;
    int length = int(token.end_ - token.start_);
    if ( length <= bufferSize )
    {
        Char buffer[bufferSize+1];
        memcpy( buffer, token.start_, length );
        buffer[length] = 0;
        count = sscanf( buffer, "%lf", &value );
    }
    else
    {
        std::string buffer( token.start_, token.end_ );
        count = sscanf( buffer.c_str(), "%lf", &value );
    }

    if ( count != 1 )
        return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token );
    currentValue() = value;
    return true;
}
int main (int argc)
{
    char str01[32], str02[32];
    unsigned int  n1, n2 , result01, result02;
    int sock, port;
    port = argc;
    //sscanf(argv[1],"%d", &port);
    if(connectToServer(&sock, port)!=0) {
        sprintf(str01,"I couldn't connect to %s:%d\n",argv[1],port);
        perror(str01);
        return -1;
    }
    printf ("give me a natural number: ");
    fgets (str01,32,stdin);
    sscanf(str01,"%u",&n1);
    printf ("give me a natural number: ");
    fgets(str02,32,stdin);
    sscanf(str02,"%u",&n2);
    remoteGCD(sock, n1, n2, &result01);
    printf("gcd(%u,%u)=%u\n", n1, n2, result01);
    remoteLCM(sock,n1, n2, &result02);
    printf("lcm(%u,%u)=%u\n", n1, n2, result02);
    close(sock);
    return 0;
}
Example #3
0
void FixFloats(idDict *dict) {
    int count = dict->GetNumKeyVals();
    for (int i = 0; i < count; i++) {
        const idKeyValue *kv = dict->GetKeyVal(i);
        for (int j = 0; j < FixupCount; j++) {
            if (kv->GetKey().Icmp(FloatFixups[j].name) == 0) {
                idStr val;
                if (FloatFixups[j].type == 1) {
                    idVec3 v;
                    sscanf(kv->GetValue().c_str(), "%f %f %f", &v.x, &v.y, &v.z);
                    sprintf(val, "%g %g %g", v.x, v.y, v.z);
                } else if (FloatFixups[j].type == 2) {
                    idMat3 mat;
                    sscanf(kv->GetValue().c_str(),	"%f %f %f %f %f %f %f %f %f ",&mat[0][0],&mat[0][1],&mat[0][2],&mat[1][0],&mat[1][1],&mat[1][2],&mat[2][0],&mat[2][1],&mat[2][2]);
                    sprintf(val, "%g %g %g %g %g %g %g %g %g",mat[0][0],mat[0][1],mat[0][2],mat[1][0],mat[1][1],mat[1][2],mat[2][0],mat[2][1],mat[2][2]);
                } else {
                    float f = atof(kv->GetValue().c_str());
                    sprintf(val, "%g", f);
                }
                dict->Set(kv->GetKey(), val);
                break;
            }
        }
    }
}
JoystickAction::JoystickAction(std::string string)
{
    type = AXIS;
    number = 0;
    joy = 0;
    joyid = 0;
    try
    {
        const char* str = string.c_str();
        if (strstr(str, "button"))
        {
            type = BUTTON;
            if (sscanf(str, "joy_%d_button_%d", &joyid, &number) < 2)
                throw string;
        }
        else if (strstr(str, "axis"))
        {
            if (sscanf(str, "joy_%d_axis_%d", &joyid, &number) < 2)
                throw string;
        }

        joy = JoystickPool::getSingleton().getJoystick(joyid);
    }
    catch (std::string e)
    {
        std::cerr << "Parse error in joystick config: " << e << std::endl;
    }
}
Example #5
0
/*
==============================
Dmc_SetKeyValue

Fill in key/values fro the teleporter
==============================
*/
void Dmc_SetKeyValue( dmc_tele_t *pTele, const char *key, const char *value )
{
    float x, y, z;

    if ( !stricmp( key, "classname" ) )
    {
        strcpy( pTele->classname, value );
    }
    else if ( !stricmp( key, "target" ) )
    {
        strcpy( pTele->target, value );
    }
    else if ( !stricmp( key, "targetname" ) )
    {
        strcpy( pTele->targetname, value );
    }
    else if ( !stricmp( key, "angles" ) )
    {
        if ( sscanf( value, "%f %f %f", &x, &y, &z ) == 3 )
        {
            pTele->angles[ 0 ] = x ;
            pTele->angles[ 1 ] = y;
            pTele->angles[ 2 ] = z;
        }
    }
    else if ( !stricmp( key, "origin" ) )
    {
        if ( sscanf( value, "%f %f %f", &x, &y, &z ) == 3 )
        {
            pTele->origin[ 0 ]  = x;
            pTele->origin[ 1 ]  = y;
            pTele->origin[ 2 ]  = z;
        }
    }
}
Example #6
0
static int flsh_erase_cmd(int argc, char* argv[])
{
    unsigned int dst, len;
    int result;

    if (( argc == 0 )||( sscanf(argv[0],"%x", &dst )!=1) )
    {
        printf(" Invalid HEX: %s.\n", argv[0]);
        return -1 ;
    }

    if( argc > 1 )
    {
        if(sscanf( argv[1], "%x", &len )!=1)
        {
            printf(" Invalid HEX: %s.\n", argv[1]);
            return -1 ;
        }
    }
    else
        len = 0x10000 ;

    printf("flsh-earse %08x, len=%08x!",dst,len);
    result=flsh_erase( dst, len );
    printf("result=%08x\n",result);

    return result;
}