Author Topic: Any problems with using ctype.h in my code?  (Read 2965 times)

stuckerj

  • Guest
Any problems with using ctype.h in my code?
« 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;
}

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Any problems with using ctype.h in my code?
« Reply #1 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...
Tim Sommers
DragonFireSDK Team

stuckerj

  • Guest
Re: Any problems with using ctype.h in my code?
« Reply #2 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

stuckerj

  • Guest
Re: Any problems with using ctype.h in my code?
« Reply #3 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...?

nednones

  • Guest
Re: Any problems with using ctype.h in my code?
« Reply #4 on: August 23, 2012, 12:07:24 am »
Just remember that declaring types from these library's need the std:: declared before hand

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Any problems with using ctype.h in my code?
« Reply #5 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.
Tim Sommers
DragonFireSDK Team