Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int findToken (char* response,char* cherche){
- const char * separators = ",";//Separateurs
- char * strToken = strtok ( response, separators );//Tokenize
- while ( strToken != NULL ) {
- if ( strstr(strToken, "value") !=0){//Value in strToken ?
- const char ch = ':';
- return atoi ( strchr(strToken, ch)+1);//Search : +1
- }
- strToken = strtok ( NULL, separators );//Next Token
- }
- return -1;
- }
- int main (){
- char response[]=" {\"status\": \"success\", \"data\": {\"counter_modes\": [\"Enabled\", \"Disabled\"], \"glob_dev_id\": 1, \"modes\": [\"Simple\", \"DirectSwitch\"], \"value\": 1, \"circuit\": \"2_01\", \"debounce\": 50, \"counter\": 2, \"counter_mode\": \"Enabled\", \"dev\": \"input\", \"mode\": \"Simple\"}} ";
- printf ("%d\n",findToken (response,"value"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement