Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int main(void)
- {
- const char *str = "{0,1,22,333,4,55,6,77777,8}";
- int tmp, tmp2, tmp3, number;
- printf("filtered number:");
- tmp = 0;
- while(1)
- {
- if( *str == '{' )
- {
- /* begin of current str */
- tmp2 = 0;
- tmp3 = 0;
- }
- if( *str == ',' || *str == '}' )
- {
- /* found a number now */
- tmp++;
- /* get how far the ptr move */
- //printf("ptr moved step: %dn", tmp2);
- /* get the digit len */
- tmp3 = tmp2 - tmp3 - 1;
- /* get the number */
- sscanf(str-tmp3, "%d", &number);
- printf("%d ", number);
- /* record current ptr possition */
- tmp3 = tmp2;
- }
- if ( *str == '}' ) break;
- str++;
- tmp2++;
- }
- printf("n");
- printf("howm any number found: %dn", tmp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement