Originally Posted by
duvernais28
My intention is to validate that an array is composed of alphas only.
Code:
#include <stdio.h>
#include <ctype.h>
int alpha_only ( const char *s )
{
if ( !*s )
{
return 0;
}
for ( ; *s; ++s )
{
if ( !isalpha ( *s ) )
{
return 0;
}
}
return 1;
}
int main ( void )
{
const char *text[] =
{
"AlphasOnly",
"abc123",
"",
"123abc",
"1a2b3c",
"Hello world",
};
size_t i;
for ( i = 0; i < sizeof text / sizeof *text; ++i )
{
printf("\"%s\" : %s\n", text [ i ],
alpha_only ( text [ i ] ) ? "yes" : "no" );
}
return 0;
}
/* my output
"AlphasOnly" : yes
"abc123" : no
"" : no
"123abc" : no
"1a2b3c" : no
"Hello world" : no
*/