Not getting any data in sprintf

60 Views Asked by At
_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
    cmd.u[0] = CMD_SG_SYNCHED;
    cmd.u[1] = uThisStation;
    cmd.u[2] = iMode;
    DSPCmdOut(&cmd);
    return 0;
}

_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
    if(S->uCMD > (MAX_CMD-1))
        return -1;
    S->cmd[S->uCMD] = *cmd;
    S->uCMD++;

    sprintf (cLogLine, "%u,%u,%u: cmd data", cmd.u[0],cmd.u[1],cmd.u[2]);                        
    WriteLine  (uhGDSLogFile, cLogLine, strlen(cLogLine));

    return 0;
}

I got this error while compile:

Left operand of . has incompatible type 'pointer to COMMAND_DESCRIPTOR'.
1

There are 1 best solutions below

0
On

since you are passing a pointer to a COMMAND_DESCRIPTOR (which is a struct i suppose) in order to assign values to struct's fields, you need to dereference it.
so, the cmd->u[0] syntax is just a (*cmd).u[0]. -> is just a syntax sugar.

change cmd.u[0] = CMD_SG_SYNCHED; to cmd->u[0] = CMD_SG_SYNCHED; and so on.

here's a nice topic : What is the difference between the dot (.) operator and -> in C++?

your full code should like following:

_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
    cmd->u[0] = CMD_SG_SYNCHED;
    cmd->u[1] = uThisStation;
    cmd->u[2] = iMode;
    DSPCmdOut(&cmd);
    return 0;
}

_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
    if(S->uCMD > (MAX_CMD-1))
        return -1;
    S->cmd[S->uCMD] = *cmd;
    S->uCMD++;

    sprintf (cLogLine, "%u,%u,%u: cmd data", cmd->u[0],cmd->u[1],cmd->u[2]);                        
    WriteLine  (uhGDSLogFile, cLogLine, strlen(cLogLine));

    return 0;
}