Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find and return first occurence of a alpha character?

Status
Not open for further replies.

Chucklez

Programmer
Jul 25, 2002
104
US
I took classes in C years ago, and have forgotten most everything I learned from them. Now I find myself in need of a simple str function.

Here is a sample bit of data:
1A-01
12C-15
8B-08
9C-05

What I need to do is return the first occurence of a non-numeric value, or basically return the letter value.

So in the first data, 'A' will be returned, then 'C', then 'B', etc. How do I do use. the str function seems to be were I need to go, but I dont know for sure.

Thanks for the help,
Chucklez
 
Or write your own: Walk through the array with a loop, checking each character with isalpha() (ctype.h) and '\0'.

Something like:
Code:
char *p = mystring;

while isalpha (*p) == 0 and *p != '\0'
  Increment p

If *p != '\0' Then *p must be alpha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top