atoi for letters? HELP

I am new here, but the site and the forum have both been realy useful for me.
Now, about my problem:
I have a char variable (c, for example) that is a 2 digit number and a single letter, with no space (example, 13b). I have to "separate" it in a int variable (i, for example) with just the number, and in a char variable (d, for example) with just the letter. For the number, I am using atoi:
i = atoi(c);
This way, i will be just the int part of c.
So, is there something like atoi, but that takes only letters? If this isn't, can you guys sujest something else?
Thak you!
char c=str[2]; ?
No.
char c[50];
because this variable is used to multiple stuff, so it's content is constantly changing. In one point of the program, c will be like the example above.
Even if I use a diferent variable for this situation, with the right size, the variable can be a 2 digit number with one letter (13a) or a 1 digit number with one letter (4d).
You could scan through the array with "isalpha(...)": http://www.cplusplus.com/reference/clibrary/cctype/isalpha/

What type of container is "c[]"? It may already have a built in member function, like "end()", to help you out.
You should use C++ streams.

1
2
3
4
stringstream ss(string(c,c+50)); //or just c if it is a null-terminated string
int number;
char ch;
ss >> number >> ch;
Last edited on
I solved, using strpbrk. Thank you anyway.
Topic archived. No new replies allowed.