tags:

views:

122

answers:

2

This is the code how can be solve

struct Tool
{
    FILE *in;
    FILE *out;
};

int main()
{
    Tool *t;
    t->in=stdin;
    t->out=stdout;
    Tool_sendcmd(Tool *tool,"SET VARIABLE value %d",3); 
}

void AGITool_sendcmd_nav(TOOLS *tool,char *command, ...)
{
    va_list ap;
    char  buffer[1024],*str;

    va_start(ap,command);
    vfprintf(tool->out, command, ap);
    va_end(ap);
    fflush(tool->out);
    buffer[0]=0;
    str=buffer;

    do {
        str=fgets(buffer,sizeof(buffer),tool->in);
    } while(str=='' && count++<5);

    printf("\n%s\n",str);
}

this is the code i have return. so tell me how to store variable argument in str.

A: 

For one thing you didn't initialize your Tool pointer in main(). There are at least a few other things wrong but that is one hint.

Sean A.O. Harney
+1  A: 

This code at least compiles and runs fine (even though I have no idea what Michel is trying to do)

#include <cstdio>
#include <cstdarg>

struct Tool
{
    FILE *in;
    FILE *out;
};

void Tool_sendcmd(Tool *tool,char *command, ...)
{
    va_list ap;
    char  buffer[1024],*str;
    int count;

    va_start(ap,command);
    vfprintf(tool->out, command, ap);
    va_end(ap);
    fflush(tool->out);
    buffer[0]=0;

    count = 0;
    do {
     str=fgets(buffer,sizeof(buffer),tool->in);
    } while(str!=NULL && count++<5);

    printf("\n%s\n",str);
}

int main()
{
    Tool *t;
    t->in=stdin;
    t->out=stdout;
    Tool_sendcmd(t,"SET VARIABLE value %d",3); 
}