DragonFireSDK Forum

Programming Discussions => Non-Game Programming => Topic started by: stuckerj on August 21, 2012, 09:42:41 pm

Title: Any problems with using ctype.h in my code?
Post by: stuckerj on August 21, 2012, 09:42:41 pm
This is to check whether text is valid on input.  Any problems with this on an iPod...?  I assume it's compatible; will it add unnecessary payload?  Thanks!

Code: [Select]
#include <ctype.h>

bool IsValidText(char *text)
//returns true if all characters are alphanumeric, hyphen or space
{
int i;
for(i=0; i < text[i]!=0; i++)
{
if(!isalnum(text[i])&&text[i]!='-'&&text[i]!=' ')
return 0;
}
return 1;
}
Title: Re: Any problems with using ctype.h in my code?
Post by: tim on August 22, 2012, 02:16:03 pm
The ctype.h library is part of the Standard C Library, so no problems.  What you need to be wary of is using anything non-standard or anything Microsoft-specific, since it won't compile for the device...
Title: Re: Any problems with using ctype.h in my code?
Post by: stuckerj on August 22, 2012, 05:55:19 pm
Excellent.  I just ran my first build for the device, and sure enough the ctype stuff works, but I'm seeing errors on other functions like sprintf_s and strcpy_s.  I fixed the same error for atoi and abs with an #include stdlib.h but the #include stdio.h and #include string.h don't seem to be working for the sprintf_s and strcps_s. 

Any recommendations there?

Code: [Select]
/App.cpp:181: error: 'sprintf_s' was not declared in this scope
/App.cpp:193: error: 'sprintf_s' was not declared in this scope
/App.cpp:274: error: 'strcpy_s' was not declared in this scope
/App.cpp:334: error: 'sprintf_s' was not declared in this scope
/App.cpp:351: error: 'sprintf_s' was not declared in this scope
/App.cpp:355: error: 'sprintf_s' was not declared in this scope
/App.cpp:400: error: 'sprintf_s' was not declared in this scope
/App.cpp:1478: error: 'strcpy_s' was not declared in this scope
/App.cpp:1479: error: 'sprintf_s' was not declared in this scope
/App.cpp:181: error: 'sprintf_s' was not declared in this scope
/App.cpp:193: error: 'sprintf_s' was not declared in this scope
/App.cpp:274: error: 'strcpy_s' was not declared in this scope
/App.cpp:334: error: 'sprintf_s' was not declared in this scope
/App.cpp:351: error: 'sprintf_s' was not declared in this scope
/App.cpp:355: error: 'sprintf_s' was not declared in this scope
/App.cpp:400: error: 'sprintf_s' was not declared in this scope
/App.cpp:1478: error: 'strcpy_s' was not declared in this scope
/App.cpp:1479: error: 'sprintf_s' was not declared in this scope
Title: Re: Any problems with using ctype.h in my code?
Post by: stuckerj on August 22, 2012, 06:16:44 pm
Looks like I got the build to work by using strcpy and sprintf instead of strcpy_s and sprintf_s.  Now I need to turn off the compiler warnings telling me the former are unsafe.   I guess the latter are Microsoft specific...?
Title: Re: Any problems with using ctype.h in my code?
Post by: nednones on August 23, 2012, 12:07:24 am
Just remember that declaring types from these library's need the std:: declared before hand
Title: Re: Any problems with using ctype.h in my code?
Post by: tim on August 23, 2012, 07:49:24 am
Those functions ending in "_s" are Microsoft-specific...  Use the versions of those without the "_s" and you will be fine.