tags:

views:

90

answers:

4
void TATTDataset::AckErrHandler(const NDataString& ErrMsg)
{
    system("echo ErrMsg: %s >> err", (const char *)ErrMsg);
    ...... code .......
}

What does this error message mean? How do I resolve it? ErrMsg.toCString() doesn't help either. Any suggestion?

EDIT:

I edited the code as suggested -

String s;    
Char *tmpStr = ErrMsg.ToCString();
s.Format("echo ErrMsg: %s >> err",tmpStr);    
system(s);

Still I get: Cannot initialize 'char *' with 'const char *'. Char *tmpStr = ErrMsg.ToCString();

A: 

the system function has only one argument, but you passed in two.

1st argument: "echo ErrMsg: %s >> err"
2nd argument: (const char *)ErrMsg

you resolve it by passing only one argument, or redifining system() to accept two arguments.

Zed
A: 

You are passing 2 arguments to system it expects one

The 2 are "echo ErrMsg: %s >> err"

(const char *)ErrMsg

I suspect you meant so combine them e.g. use snprintf

Although if this is actual code I would output the error message to a file directly rather than use system e.g. fprintf

Mark
+1  A: 

The system() call has really just one argument. What you are trying to do is to let system() act like printf(), which is obviously not the way it was designed to.

You cant try to use a string class which can do some parsing or make a temporary buffer and use sprintf()

Chaosteil
<quote>obviously not the way it was designed to.</quote>: obvious is a subjective term. If it was obvious then the poster --obviously-- would not have made the mistake.
Martin York
+1  A: 

As already mentioned system() takes only one argument (a string).

If ErrMsg.toCString() returns a MFC CString then you can try this:

void TATTDataset::AckErrHandler(const NDataString& ErrMsg)
{
    CString s;
    s.Format("echo ErrMsg: %s >> err", ErrMsg.toCString());
    system(s);
    ...... code .......
}
Nick D
Char *str;const char* ToCString() const { return str; }