Click here to Skip to main content
15,894,343 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
SuggestionRe: Macro analysis - help wanted Pin
David Crow18-Dec-18 10:04
David Crow18-Dec-18 10:04 
GeneralRe: Macro analysis - help wanted Pin
Vaclav_18-Dec-18 13:32
Vaclav_18-Dec-18 13:32 
QuestionPlacing the dialog bar Pin
manoharbalu17-Dec-18 23:12
manoharbalu17-Dec-18 23:12 
AnswerRe: Placing the dialog bar Pin
Richard MacCutchan17-Dec-18 23:48
mveRichard MacCutchan17-Dec-18 23:48 
GeneralRe: Placing the dialog bar Pin
manoharbalu18-Dec-18 1:42
manoharbalu18-Dec-18 1:42 
GeneralRe: Placing the dialog bar Pin
Richard MacCutchan18-Dec-18 1:54
mveRichard MacCutchan18-Dec-18 1:54 
GeneralRe: Placing the dialog bar Pin
manoharbalu18-Dec-18 1:59
manoharbalu18-Dec-18 1:59 
QuestionRe: Placing the dialog bar Pin
David Crow18-Dec-18 4:19
David Crow18-Dec-18 4:19 
GeneralRe: Placing the dialog bar Pin
Richard MacCutchan18-Dec-18 4:49
mveRichard MacCutchan18-Dec-18 4:49 
GeneralRe: Placing the dialog bar Pin
Richard MacCutchan18-Dec-18 6:28
mveRichard MacCutchan18-Dec-18 6:28 
GeneralRe: Placing the dialog bar Pin
manoharbalu18-Dec-18 22:55
manoharbalu18-Dec-18 22:55 
GeneralRe: Placing the dialog bar Pin
mo149219-Dec-18 0:18
mo149219-Dec-18 0:18 
GeneralRe: Placing the dialog bar Pin
mo149219-Dec-18 1:44
mo149219-Dec-18 1:44 
GeneralRe: Placing the dialog bar Pin
manoharbalu20-Dec-18 2:01
manoharbalu20-Dec-18 2:01 
GeneralRe: Placing the dialog bar Pin
mo149220-Dec-18 12:31
mo149220-Dec-18 12:31 
GeneralRe: Placing the dialog bar Pin
manoharbalu20-Dec-18 17:40
manoharbalu20-Dec-18 17:40 
GeneralRe: Placing the dialog bar Pin
Richard MacCutchan19-Dec-18 4:20
mveRichard MacCutchan19-Dec-18 4:20 
QuestionPassing / modifying char* to/ by function. Pin
Vaclav_16-Dec-18 16:33
Vaclav_16-Dec-18 16:33 
AnswerRe: Passing / modifying char* to/ by function. Pin
CPallini16-Dec-18 21:23
mveCPallini16-Dec-18 21:23 
AnswerRe: Passing / modifying char* to/ by function. Pin
Richard MacCutchan16-Dec-18 22:30
mveRichard MacCutchan16-Dec-18 22:30 
You could reduce the number of buffers you are using, as that seems to complicate your code. You are also trying to return FullMessage which is a temporary buffer inside the function. So as soon as you return from the function that buffer's memory space is free to be overwritten. And what is that exit(1) call there for? No wonder you never return from your function. You need something simple like (using C style only):
C++
#define MAX_BUFFER 100
char * CLASS_LCM1602::BuildMessage(char *title, int value)
{
    // allocate a new buffer for the return message
    char* buffer = (char*)malloc(MAX_BUFFER );
    snprintf(buffer, MAX_BUFFER , "%s %d", title, value); // this assumes 100 characters is enough
    
    return buffer;
}

And then the call is:
C++
char *message = i2c.BuildMessage(title, value);
printf("%s\n", message);
free(message); // release the buffer when finished with


modified 17-Dec-18 5:03am.

GeneralRe: Passing / modifying char* to/ by function. Pin
CPallini16-Dec-18 22:56
mveCPallini16-Dec-18 22:56 
GeneralRe: Passing / modifying char* to/ by function. Pin
Richard MacCutchan16-Dec-18 23:01
mveRichard MacCutchan16-Dec-18 23:01 
GeneralRe: Passing / modifying char* to/ by function. Pin
Vaclav_17-Dec-18 3:26
Vaclav_17-Dec-18 3:26 
GeneralRe: Passing / modifying char* to/ by function. Pin
Richard MacCutchan17-Dec-18 3:50
mveRichard MacCutchan17-Dec-18 3:50 
GeneralRe: Passing / modifying char* to/ by function. Pin
leon de boer17-Dec-18 18:48
leon de boer17-Dec-18 18:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.