I have a very basic question, if I have a string of chars like this: char charv1[6] = "v445"
or v666
How can I get the numbers and turn them into a single integer with value: 445
or 666
?
I have been trying this code but something goes wrong ...:
size = (strlen(charv1)-1);
for(aux = size; aux > 0; aux--){
if(aux == (size)){
v1 = charv1[aux]-'0';
}
else{
aux2 = (charv1[aux]-'0')*10;
printf("%d\n", aux2);
v1 = v1 + aux2;
}
}
charv1
contains the string: v445
etc
I remember a few years ago, I did it recursively but I do not remember how, but now I do not need an elegant solution ... I need one that just works.