arrays - C language strtok() specific element after delimiter -


i have series of strings each letters, whitespace, numbers , $. can't seem figure out how number(s) following $? example,

char s[50]= "i have $20 , 3 hours left work."; char t[50]= "he might have 4 left have $7."; char u[50]= "$29 , 30 equal 59 dollars."; /* i'm assuming strtok, since makes sense me */ 

expected output

20  7 29 

any appreciated!

sample strchr , sscanf

#include <stdio.h> #include <string.h>  void print(int val){     printf("%d\n", val); }  void get(const char *s, void (*callback)(int)){     int value;     while((s = strchr(s, '$')) != null){         if(1==sscanf(++s, "%d", &value)){             callback(value);         }     } }  int main(void){     char s[50]= "i have $20 , 3 hours left work.";     char t[50]= "he might have 4 left have $7.";     char u[50]= "$29 , 30 equal 59 dollars.";      char *a[] = { s, t, u};      for(int = 0; < sizeof(a)/sizeof(*a); ++i){         get(a[i], print);     }     return 0; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -