fork download
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #define MAX_SIZE 100
  7.  
  8. char *findNumber(char *str1)
  9. {
  10. char *num1 = malloc(MAX_SIZE);
  11. // using "strlen(str1)+1" instead of MAX_SIZE might be preferred
  12. int i = 0, j = 0;
  13. while(str1[i] != '\0') {
  14. if(isdigit(str1[i])) {
  15. num1[j] = str1[i];
  16. j++;
  17. }
  18. i++;
  19. }
  20. num1[j] = '\0';
  21. return num1;
  22. }
  23.  
  24. int main(int argc, const char* argv[])
  25. {
  26. char str2[] = "!3254";
  27. printf(findNumber(str2));
  28. return 0;
  29. }
Success #stdin #stdout 0s 1964KB
stdin
Standard input is empty
stdout
3254