从下列字符串中提起字符串 temperature

从下列字符串中提起字符串 temperature后面的数据 12.5,注意提取的数据以 ] 结束,可能数字是12.5,也可能123.5,意思是提取的数据宽度有变化时,也能提取 "Asia/Shanghai,server_time:1643418869,location:[33.06,107.03],result:{realtime:{status:ok,temperature:[12.5]"humidity:[0.95

一个实现:

#include <stdio.h>

int main(void){
    
    char str[256];
    char * findStr="temperature";
    gets(str);
    
    char ch;
    int i=0;
    int j=0;
    int loop = 1;
    int sameLength=0;
    char result[25];
    int k=0;
    while(loop){
        
    //    printf("1\n");
        while(findStr[j]==str[i]&&str[i]!='\0'&&findStr[j]!='\0'){
        //    printf("2\n");
            i++;
            j++;
            sameLength++;
        }
    //    printf("i=%d,j=%d,sameLength=%d\n",i,j,sameLength);
        if(sameLength==11){
        //    printf("str[i]=%s\n",str+i);
            i=i+2; 
            while(str[i]!=']'){
                result[k] = str[i];
                i++;
                k++;                
            }
            result[k]='\0';
        //    printf("result=%s\n",result);
            loop=0;
        }
        
        if(sameLength==0){
            i++;
        } 
        sameLength=0;
        j=0;
        
        
    }
    
    puts(result);
    
}