S
spl
What is the best way to check any ASCII characters between 33 to 47
exists in a char*?
exists in a char*?
spl said:What is the best way to check any ASCII characters between 33 to 47
exists in a char*?
spl said:What is the best way to check any ASCII characters between 33 to 47
exists in a char*?
santosh said:For maximal portability use the ispunct() function. Otherwise use
something like:
if (ch >= 33 && ch <= 47) /* ... */
spl said:No, this is fine only, if I search a single character, but mine is 256
character string, in that I have to find any occurance of the Ascii
characters btw 34 to 47.
spl said:No, this is fine only, if I search a single character, but mine is 256
character string, in that I have to find any occurance of the Ascii
characters btw 34 to 47.
Insufficiently specified... Do you need simply to determine whether
at least one character in the range is present, or identify all
instances of characters in that range?
spl said:at least one character in the range is present...
I feel Santosh solution would be fine... but if the string goes very
lengthy, let us say more than 1000 character, then loop will go for
1000 time. So performance vice it will be slow?
spl said:I feel Santosh solution would be fine... but if the string goes very
lengthy, let us say more than 1000 character, then loop will go for
1000 time. So performance vice it will be slow?
spl said:at least one character in the range is present...
I feel Santosh solution would be fine... but if the string goes very
lengthy, let us say more than 1000 character, then loop will go for
1000 time. So performance vice it will be slow?
Morris said:Probably. The search could also be done using strchr(), which
/might/ result in a faster search depending on compiler
optimization and/or machine architecture - on the other hand a
really smart compiler might be able to arrive at those same
optimizations by examining the loop code...
What is the best way to check any ASCII characters between 33 to 47
exists in a char*?
#include said:int checkFor33to47(const char *str)
{
char set[] = {33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 0};
char *result = strpbrk(str, set);
return result != NULL;
}
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.