Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void)
  6. {
  7.  
  8. const char *str = "{0,1,22,333,4,55,6,77777,8}";
  9. int tmp, tmp2, tmp3, number;
  10.  
  11. printf("filtered number:");
  12.  
  13. tmp = 0;
  14. while(1)
  15. {
  16. if( *str == '{' )
  17. {
  18. /* begin of current str */
  19. tmp2 = 0;
  20. tmp3 = 0;
  21. }
  22.  
  23. if( *str == ',' || *str == '}' )
  24. {
  25. /* found a number now */
  26. tmp++;
  27.  
  28. /* get how far the ptr move */
  29. //printf("ptr moved step: %dn", tmp2);
  30.  
  31. /* get the digit len */
  32. tmp3 = tmp2 - tmp3 - 1;
  33.  
  34. /* get the number */
  35. sscanf(str-tmp3, "%d", &number);
  36. printf("%d ", number);
  37.  
  38. /* record current ptr possition */
  39. tmp3 = tmp2;
  40. }
  41.  
  42. if ( *str == '}' ) break;
  43.  
  44. str++;
  45. tmp2++;
  46. }
  47. printf("n");
  48. printf("howm any number found: %dn", tmp);
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement