0

I have a char* array which looks like this "T 20" and I'd like to extract the "20" and convert it in to an integer. I was thinking of using atoi() but it seems that function will operate on the entire string, not just the bits I want. Memory is a bit tight so is there a function similar to atoi() which allows you to specify which charters to operate on?

asked Jun 22, 2017 at 10:17

1 Answer 1

4

How about

char array[5] = "T 20";
int num = atoi(array+2);

This obviously assumes that all your strings are of the same format "A NN". If not, you can try parsing it using strtok(). See this excellent answer.

answered Jun 22, 2017 at 10:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.