I got it to work finally.  For some reason, doing the snprintf as
described in my previous post did not always work:
 
    snprintf(this_index, strlen((char *)*my_loop_context),
       "%s",(const char*)*my_loop_context); 

So I tried using a c++ string rather than this_index for the temporary
variable used in the comparisons:

    char this_index[SPRINT_MAX_LEN];
    std::string indexString((char *)*my_loop_context);

    if(strcmp(indexString.c_str(),"title1")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title2");    
    } else if (strcmp(indexString.c_str(),"title2")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title3");        
    } else if (strcmp(indexString.c_str(),"title3")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title4");        
    }else{
       return NULL;
    }

I also found that using a different character array works as well:

    char this_index[SPRINT_MAX_LEN];
    char temp_index[SPRINT_MAX_LEN];
    snprintf(temp_index, SPRINT_MAX_LEN,
       "%s",(const char*)*my_loop_context); 

    if(strcmp(temp_index,"title1")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title2");    
    } else if (strcmp(temp_index,"title2")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title3");        
    } else if (strcmp(temp_index,"title3")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title4");        
    }else{
       return NULL;
    }

-----Original Message-----
From: Toth, Gregory S 
Sent: Tuesday, September 19, 2006 1:48 PM
Cc: [email protected]
Subject: RE: How to index a table with a string

 
That worked better for the bookTable_get_first_data_point method.  Now I
am trying to use the my_loop_context in the
bookTable_get_next_data_point(void **my_loop_context,
                              void **my_data_context,
                              netsnmp_variable_list * put_index_data,
                              netsnmp_iterator_info *mydata) {

    char this_index[SPRINT_MAX_LEN];
 
   //this printf shows the setting from the get_first_data_point method
    printf("my_loop_context = %s\n",(char *)*my_loop_context);
  
    snprintf(this_index, strlen((char *)*my_loop_context),
       "%s",(const char*)*my_loop_context); 
 
    //this printf does not show the setting even though it should
    printf("bookTable_get_next_data_point this index %s \n",this_index);

I don't seem to be able to access the data from my_loop_context in order
to increment to the next datapoint.
-----Original Message-----
From: Dave Shield [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 19, 2006 11:08 AM
To: Toth, Gregory S
Cc: [email protected]
Subject: Re: How to index a table with a string

On 19/09/06, Toth, Gregory S <[EMAIL PROTECTED]> wrote:

>     char this_index[SPRINT_MAX_LEN]  = "title1";
>     snmp_set_var_value(vptr, (u_char *) &this_index ,
>                        sizeof(this_index) );

try
       snmp_set_var_value( vptr, this_index, strlen(this_index));

The size of 'this_index' is SPRINT_MAX_LEN, but the index string doesn't
use all of this buffer.  And 'this_index' is already a pointer to the
value, so you don't need to take the address again.

Dave

------------------------------------------------------------------------
-
Take Surveys. Earn Cash. Influence the Future of IT Join
SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE
V
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to