fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void) {
  6. char* str = "RING\n\n+CLIP: \"7987100500\",145,,,\"\",0";
  7. char* number = "";
  8. int max = 0;
  9. for(int i = 0; i < strlen(str); i++){
  10. int j = 0;
  11. char *str2 = "";
  12. char *str3 = "";
  13. while(str[i] >= '0' && str[i] <= '9'){
  14. j++;
  15. size_t len = strlen(str2);
  16. str3 = malloc(len + 2); /* one for extra char, one for trailing zero */
  17. strcpy(str3, str2);
  18. str3[len] = str[i];
  19. str3[len + 1] = '\0';
  20. if(strlen(str2))
  21. free(str2);
  22. str2 = malloc(len+2);
  23. strcpy(str2, str3);
  24. free(str3);
  25. if(i<strlen(str))
  26. i++;
  27. }
  28. if(j>max){
  29. if(strlen(number))free(number);
  30. number = malloc(strlen(str2)+2);
  31. strcpy(number,str2);
  32. number[strlen(str2)+1] = '\0';
  33. max=j;
  34. }
  35. }
  36.  
  37. printf("%s\n",number);
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 2300KB
stdin
Standard input is empty
stdout
7987100500