#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
    char* str = "RING\n\n+CLIP: \"7987100500\",145,,,\"\",0";
    char* number = "";
    int max = 0;
    for(int i = 0; i < strlen(str); i++){
        int j = 0;
        char *str2 = "";
        char *str3 = "";
        while(str[i] >= '0' && str[i] <= '9'){
            j++;
            size_t len = strlen(str2);
            str3 = malloc(len + 2); /* one for extra char, one for trailing zero */
            strcpy(str3, str2);
            str3[len] = str[i];
            str3[len + 1] = '\0';
            if(strlen(str2))
                free(str2);
            str2 = malloc(len+2);
            strcpy(str2, str3);
            free(str3);
            if(i<strlen(str))
                i++;
        }
        if(j>max){
            if(strlen(number))free(number);
            number = malloc(strlen(str2)+2);
            strcpy(number,str2);
            number[strlen(str2)+1] = '\0';
            max=j;
        }
    }

    printf("%s\n",number);
    return 0;
}
