sscanf error

G

GrispernMix

bool variant_t::Convert( fieldtype_t newType )
{
if ( newType == fieldType )
{
return true;
}

//
// Converting to a null value is easy.
//
if ( newType == FIELD_VOID )
{
Set( FIELD_VOID, NULL );
return true;
}

//
// FIELD_INPUT accepts the variant type directly.
//
if ( newType == FIELD_INPUT )
{
return true;
}

switch ( fieldType )
{
case FIELD_INTEGER:
{
switch ( newType )
{
case FIELD_FLOAT:
{
SetFloat( (float) iVal );
return true;
}

case FIELD_BOOLEAN:
{
SetBool( iVal != 0 );
return true;
}
}
break;
}

case FIELD_FLOAT:
{
switch ( newType )
{
case FIELD_INTEGER:
{
SetInt( (int) flVal );
return true;
}

case FIELD_BOOLEAN:
{
SetBool( flVal != 0 );
return true;
}
}
break;
}

//
// Everyone must convert from FIELD_STRING if possible, since
// parameter overrides are always passed as strings.
//
case FIELD_STRING:
{
switch ( newType )
{
case FIELD_INTEGER:
{
if (iszVal != NULL_STRING)
{
SetInt(atoi(STRING(iszVal)));
}
else
{
SetInt(0);
}
return true;
}

case FIELD_FLOAT:
{
if (iszVal != NULL_STRING)
{
SetFloat(atof(STRING(iszVal)));
}
else
{
SetFloat(0);
}
return true;
}

case FIELD_BOOLEAN:
{
if (iszVal != NULL_STRING)
{
SetBool( atoi(STRING(iszVal)) != 0 );
}
else
{
SetBool(false);
}
return true;
}

case FIELD_VECTOR:
{
Vector tmpVec = vec3_origin;
if (sscanf(STRING(iszVal), "[%f %f %f]", &tmpVec[0], &tmpVec[1],
&tmpVec[2]) == 0)
{
// Try sucking out 3 floats with no []s
sscanf(STRING(iszVal), "%f %f %f", &tmpVec[0], &tmpVec[1],
&tmpVec[2]);
}
SetVector3D( tmpVec );
return true;
}

case FIELD_COLOR32:
{
int nRed = 0;
int nGreen = 0;
int nBlue = 0;
int nAlpha = 255;

problem-> sscanf(STRING(iszVal), "%d %d %d %d", &nRed, &nGreen, &nBlue,
&nAlpha);
SetColor32( nRed, nGreen, nBlue, nAlpha );
return true;
}

case FIELD_EHANDLE:
{
// convert the string to an entity by locating it by classname
CBaseEntity *ent = NULL;
if ( iszVal != NULL_STRING )
{
// FIXME: do we need to pass an activator in here?
ent = gEntList.FindEntityByName( NULL, iszVal, NULL );
}
SetEntity( ent );
return true;
}
}

break;
}

case FIELD_EHANDLE:
{
switch ( newType )
{
case FIELD_STRING:
{
// take the entities targetname as the string
string_t iszStr = NULL_STRING;
if ( eVal != NULL )
{
SetString( eVal->GetEntityName() );
}
return true;
}
}
break;
}
}

// invalid conversion
return false;
}
Can anyone tell me a good reason why i might be getting a sscanf
identifier not found error other than stdio.h missing

- it doesnt appear to be a syntax error
-
 
V

Victor Bazarov

GrispernMix said:
[...]
Can anyone tell me a good reason why i might be getting a sscanf
identifier not found error other than stdio.h missing

No. Do you actually have 'stdio.h' included?
- it doesnt appear to be a syntax error

No, it does not.

Preserve your file (back it up somewhere), remove everything from
that function except the line that gives you the error and some other
stuff for it to work, and then drop all other includes and functions
from that file (IOW, distill it to this line only). Then see if it
compiles. Make sure you only include the headers you need.

V
 
G

GrispernMix

could it be problem with my compiler microsoft visual 2005, i have
another sscanf problem which i hope can show me why i keep getting the
identifer not found

#include <stdio.h>
#include <wchar.h>
#include <conio.h>

int main( void )
{
char tokenstring[] = "15 12 14...";
char s[81];
char c;
int i;
float fp;

// Input various data from tokenstring:
// max 80 character string:
sscanf( tokenstring, "%80s", s ); // C4996
sscanf( tokenstring, "%c", &c ); // C4996
sscanf( tokenstring, "%d", &i ); // C4996
sscanf( tokenstring, "%f", &fp ); // C4996
// Note: sscanf is deprecated; consider using sscanf_s instead

// Output the data read
printf( "String = %s\n", s );
printf( "Character = %c\n", c );
printf( "Integer: = %d\n", i );
printf( "Real: = %f\n", fp );
getch();

}
 
G

GrispernMix

IT WAS THE DEPRECIATION!!!!!! pardon my loudness, but the sscanf was
fixed with a mere sscanf_s
 
V

Victor Bazarov

GrispernMix said:
could it be problem with my compiler microsoft visual 2005, i have
another sscanf problem which i hope can show me why i keep getting the
identifer not found

#include <stdio.h>
#include <wchar.h>
#include <conio.h>

This is non-standard.
int main( void )
{
char tokenstring[] = "15 12 14...";
char s[81];
char c;
int i;
float fp;

// Input various data from tokenstring:
// max 80 character string:
sscanf( tokenstring, "%80s", s ); // C4996
[...]
}

If I remove 'getch', it compiles fine here. There must be something
in your project settings. If you need to find a solution specific
for VC++ v8, post to 'microsoft.public.vc.language' where you can name
the compiler settings (off-topic here). I bet folks there can help.

<OT>
VC++ v8 does report 'sscanf' as "deprecated" (for whatever reason),
but compiles nonetheless. Could it be you have all warnings treated
as errors? Add [#pragma warning] to ignore it.
</OT>

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top