Click here to Skip to main content
15,889,651 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I need your help Pin
CPallini14-Sep-14 18:46
mveCPallini14-Sep-14 18:46 
QuestionCan i trust the result of clock_getres? Pin
elelont212-Sep-14 1:34
elelont212-Sep-14 1:34 
AnswerRe: Can i trust the result of clock_getres? Pin
Stefan_Lang12-Sep-14 1:50
Stefan_Lang12-Sep-14 1:50 
AnswerRe: Can i trust the result of clock_getres? Pin
CPallini12-Sep-14 2:49
mveCPallini12-Sep-14 2:49 
Questionwhat is C language ? Pin
uetester111-Sep-14 22:01
uetester111-Sep-14 22:01 
AnswerRe: what is C language ? Pin
CPallini11-Sep-14 22:10
mveCPallini11-Sep-14 22:10 
GeneralRe: what is C language ? Pin
Albert Holguin16-Sep-14 8:31
professionalAlbert Holguin16-Sep-14 8:31 
QuestionInitializing structure with pointers to char arrays - bug Pin
Vaclav_11-Sep-14 4:59
Vaclav_11-Sep-14 4:59 
<pre lang="text">

Could someone please help me to find my bug.
This is C++ code "running" on Arduino.
It compiles and runs ,but...
I am using a struct to define / collect data which belong together.
The bug is when I enter a character array (using pointer) into the structure variable, also a character array.
The actual variable I am having problem with is ctextPrompts. I am sure there will be more, but this is the first bug.
It is entered properly - verified by test code immediately after - see TOK here note.
However, when I initialize next member of the struture cTextEntry - it wipes out the ctextPrompts.
Initializing next structure member ctextEmulate puts ctextEmulate characters into ctextPrompts.

This is my first attempt to utilize pointers and structure and I MUST have done something really stupid to cause this bug.

I am using LCD to debug the code.

Since the rest of the code works as expected I am pretty sure it is not a "memory" issue, I do verify the size of available RAM on initialization.
I doubt it is a Arduino compiler issue, just plain wrong usage of pointers which I just do not see.

I do apologize for the long code, but I feel it would help to see the debbuging attempts I have made so far.

Thanks for your help.
Cheers
Vaclav

PS While testing I am using both pointer (*) and indexing [0] with same results



</pre>char


*ctextEntry[] ={

" ", " "," " };
// emulating data
char *ctextEmulate[] = { // emulate entries
"14260123 ", // start frequency
"14360000 ", // end frequency
"10000 ", // step frequency
"1 ", // step speed
"1 ", // 0 single shot 1 repeat
"Option" //
}; // temporary not completed

char *ctextPrompts[] ={
"Start frequency ","End frequency ","Step frequency ","Step speed ","Single / Repeat","Optional "};



typedef struct DataRecordTAG
{
char *cPrompts[]; // prompt text
char *cEmulate[]; // emulate input
char *cEntry[]; // response
char cTEST;
int iIndex;
}
DataRecord;

DataRecord Record[DATA_STRUCT]; // variable

int igRecordIndex = 0; // global access to records

.......

void InitializeRecords(void)
{
// changed to global igRecordIndex igRecordIndex
// igRecordIndex

// initialize prompts and some test entries
int iPromptIndex = 0;
for(igRecordIndex = 0; igRecordIndex != DATA_STRUCT ; igRecordIndex++) // fence post error Optional missing
{
Record[igRecordIndex].iIndex = igRecordIndex; //test index not really needed
/* TOK
#ifdef FLOW_LCD
lcd.clear();
lcd.print("Record[igRecordIndex].iIndex"); //too long
lcd.setCursor(0,1);
lcd.print(Record[igRecordIndex].iIndex); // too long
delay(DELAY_LCD);
#endif
*/
#ifdef FLOW_LCD
TOK verified
lcd.clear();
lcd.print("cPrompts empty ");
lcd.setCursor(0,1);
lcd.print(*Record[0].cPrompts);
delay(5*DELAY_LCD);

#endif


// prompt bug
*Record[igRecordIndex].cPrompts = ctextPrompts[igRecordIndex];
//ReadRecords();
#ifdef FLOW_LCD
TOK here
lcd.clear();
lcd.print("cPrompts entered");
lcd.setCursor(0,1);
lcd.print(*Record[0].cPrompts);
delay(5*DELAY_LCD);

#endif

/*
// BUG writes over previous record how ??
for(int i = 0; i < DATA_STRUCT; i++)
{
#ifdef FLOW_LCD
lcd.clear();
lcd.print("igRecordIndex");
lcd.setCursor(0,1);
lcd.print(igRecordIndex);
delay(DELAY_LCD);

lcd.clear();
lcd.print("Record[i].cPrompts");
lcd.setCursor(0,1);
lcd.print(*Record[i].cPrompts);
delay(5*DELAY_LCD);

#endif
}
// BUG writes over previous record how ??

*/

/* TOK
#ifdef FLOW_LCD
lcd.clear();
lcd.print("Record[igRecordIndex].cPrompts"); //too long
lcd.setCursor(0,1);
lcd.print(*Record[igRecordIndex].cPrompts); // too long
delay(DELAY_LCD);
#endif
*/


Record[igRecordIndex].cEntry[0] = ctextEntry[igRecordIndex]; // [DIGITS]

#ifdef FLOW_LCD
BUG now the cPrompts is empty
lcd.clear();
lcd.print("cText entered");
lcd.setCursor(0,1);
lcd.print(*Record[0].cPrompts);
delay(5*DELAY_LCD);

#endif






*Record[igRecordIndex].cEmulate = ctextEmulate[igRecordIndex]; // emulate input
#ifdef FLOW_LCD
BUG the cPrompts contains ctextEmulate - index 0
lcd.clear();
lcd.print("ctextEmulate entered");
lcd.setCursor(0,1);
lcd.print(*Record[0].cPrompts);
delay(5*DELAY_LCD);

#endif





/* TOK
#ifdef FLOW_LCD
lcd.clear();
lcd.print("Emulate "); //too long
lcd.setCursor(0,1);
lcd.print(Record[igRecordIndex].cEmulate); // too long
delay(DELAY_LCD);
#endif
*/

}

igRecordIndex = 0;
ReadRecords();
for(;;);

/* TOK
#ifdef FLOW_SERIAL
Serial.println("Prompts initialized DONE ");
#endif

#ifdef FLOW_LCD
lcd.clear();
lcd.print("Prompts initialized DONE ");
delay(DELAY_LCD);
#endif
*/
}
QuestionRe: Initializing structure with pointers to char arrays - bug Pin
CPallini11-Sep-14 5:09
mveCPallini11-Sep-14 5:09 
AnswerRe: Initializing structure with pointers to char arrays - bug Pin
Vaclav_11-Sep-14 6:30
Vaclav_11-Sep-14 6:30 
AnswerRe: Initializing structure with pointers to char arrays - bug Pin
ahmad_ali11-Sep-14 5:10
ahmad_ali11-Sep-14 5:10 
GeneralRe: Initializing structure with pointers to char arrays - bug Pin
Vaclav_11-Sep-14 6:44
Vaclav_11-Sep-14 6:44 
GeneralRe: Initializing structure with pointers to char arrays - bug Pin
Vaclav_11-Sep-14 6:47
Vaclav_11-Sep-14 6:47 
GeneralSOLVED Re: Initializing structure with pointers to char arrays - bug Pin
Vaclav_11-Sep-14 7:14
Vaclav_11-Sep-14 7:14 
QuestionCalling a web service from Visual C++ 2008 native Pin
Hadi Dayvary11-Sep-14 3:09
professionalHadi Dayvary11-Sep-14 3:09 
QuestionExecute Shell Script and Batch Files Pin
AmbiguousName10-Sep-14 23:37
AmbiguousName10-Sep-14 23:37 
AnswerRe: Execute Shell Script and Batch Files Pin
Richard MacCutchan10-Sep-14 23:47
mveRichard MacCutchan10-Sep-14 23:47 
GeneralRe: Execute Shell Script and Batch Files Pin
AmbiguousName11-Sep-14 0:23
AmbiguousName11-Sep-14 0:23 
GeneralRe: Execute Shell Script and Batch Files Pin
Richard MacCutchan11-Sep-14 0:31
mveRichard MacCutchan11-Sep-14 0:31 
GeneralRe: Execute Shell Script and Batch Files Pin
AmbiguousName11-Sep-14 0:49
AmbiguousName11-Sep-14 0:49 
GeneralRe: Execute Shell Script and Batch Files Pin
Richard MacCutchan11-Sep-14 1:20
mveRichard MacCutchan11-Sep-14 1:20 
Questiondeterminant of matrix in c N*N dimension return process kill .I took from net can anyone help me out where exactly its making this issue and how to overcome this issue.As per my program i pass @dimensional matrix of order x=100; Pin
mybm110-Sep-14 20:06
mybm110-Sep-14 20:06 
AnswerRe: determinant of matrix in c N*N dimension return process kill .I took from net can anyone help me out where exactly its making this issue and how to overcome this issue.As per my program i pass @dimensional matrix of order x=100; Pin
Stefan_Lang11-Sep-14 2:51
Stefan_Lang11-Sep-14 2:51 
GeneralRe: determinant of matrix in c N*N dimension return process kill .I took from net can anyone help me out where exactly its making this issue and how to overcome this issue.As per my program i pass @dimensional matrix of order x=100; Pin
mybm111-Sep-14 2:55
mybm111-Sep-14 2:55 
GeneralRe: determinant of matrix in c N*N dimension return process kill .I took from net can anyone help me out where exactly its making this issue and how to overcome this issue.As per my program i pass @dimensional matrix of order x=100; Pin
Stefan_Lang11-Sep-14 4:40
Stefan_Lang11-Sep-14 4:40 

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.