Comparison between character and number.

Environment : Visual C++

Can anyone give me the codings on how do i determen each character in terms of the type.

For example :

SE100

S=Character
E=Character
1=Number
0=Number
0=Number


I want to evaluate and see weather S is a character, E is a character, 1 is a number and as follows.


Regards

Eugene

eugene007Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
inprasConnect With a Mentor Commented:
Hi
take each char and check with function IsAlpha(ch) it will return no zero if its alphabet or if its any other thing other than alphabet it returns zero
U can use isalnum to check for number if isalpha returns 0

char ch[5] = "SE100";
for (int i = 0; i<=4 ; i++)
 if (isalpha(ch[i]))
// alphabet
else
 if(isalnum(ch[i])
     //Number

Hope this helps
anuy way what happened to select statement U did not give structure?
Regards
0
 
inprasCommented:
A program?
here itis
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void main( void )
{
      char chStr[10] = "SE100";
      int k = strlen(chStr);
      for (int i = 0; i <= k ; i++)
      {
            if (isalpha(chStr[i]))
                  printf("Character\n");
            else
                  if(isalnum(chStr[i]))
                        printf("Number\n");
      }
}
Regards
0
 
eugene007Author Commented:
Hi inpras...sorry that i did not send you that comment...because busy for christmas...ill send it to you as soon as possible..and thanks for the cooding its working great.

Regards

Eugene
0
All Courses

From novice to tech pro — start learning today.