[Solved] C how to identify function exist or not [closed]


You could define a struct like this:

struct tags {
    const char *name;
    int maxlen;
    char value[128];
};

struct tags tagList[] = {
    { "34", 32, 0 },
    { "43", 16, 0 },
    { "11", 32, 0 },
    ...
};

Then you could write your loop like this:

for(int idx=0;idx<inum;idx++){
    if( strlen(ArrLeftVar[idx]) < 1 )
        break ;
    for (int tagIdx=0; tagIdx < (sizeof(tagList) / sizeof(tagList[0]); tagIdx++) {
        if( strcmp(ArrLeftVar[idx],tagList[tagIdx].name) == 0 ){ 
            strncpy(tagList[tagIdx].value,
                    ArrRightVal[idx],
                    tagList[tagIdx].maxlen - 1 );
            tagList[tagIdx].value[tagList[tagIdx].maxlen - 1] = '\0';
            break;
        }
    }
}

If at any time you need to add/remove tags, you only have to change the tag list array instead of a large if/else block.

solved C how to identify function exist or not [closed]