is there a function in c that lets me look at the next char in an array? Also where could I find this information on my own, I tried Google and looking for existing threads on this site.
I am trying to pull numbers from a line, and store those numbers. So I want to do something like
if(c = a number and c "next character" is not a number){value is = value*10+c-'0', store number}
If the current character is array[i], the next character is array[i+1].
You could write a method to do this:
char next_char(char *array, int i, int size){
    return (++i) < size ? array[i] : '\0';
}
EDIT: After reading your question something like this may be reasonable.
if(isdigit(array[i]) && !isdigit(next_char(array,i,size)){
    ..
}
A better solution would be a for loop:
int val = 0;
for(i = 0; i < size; i++){
    if(isdigit(i)){
        val = 10 * val + array[i] - '0';
    }else{
        // Store the value
        val = 0;            
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With