|
johnstonsk wrote:
must be doing something ese wrong, because it keeps crashing.
Post the array declarations, and the code that causes the crash, and we'll see what we can do for you
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
The error I get is there is a call to undefined function memcpy()
I included the string.h
Can this function only copy chars or strings?
The program that I have reads data from a pci card and puts it in the structures below:
This data gets updated 2 times a second.
struct TSimHeader
{
char Name[47][20];
char Unit[47][20];
double Min[47];
double Max[47];
int SignalCount;
int SimStatus;
}static TSimHeader_arr[10];
struct TSimSignal
{
double Value[47];
double TimeStamp;
}static TSimSignal_arr[10];
I have added a new feature to the program that will allow the recording of data.
This will be done by writiing the data to a *csv file so it can be read in excel.
Since the data in the structures is getting updated 2 times a second I thought that it would be good to just make a new array and copy the data to the array so, if the user wanted to start recording the data it would be there ready to start recording. That is why I call the copyData() function everytime the data is updated.
I also created arrays that are of the same type and size of the ones in the struct
char name[47][20];
char unit[47][20];
double min[47];
double max[47];
double value[47];
Below is the copyData() function:
void RFMAccess::copyData(){
if(firstTime1){
memcpy(pflight_data->name, TSimHeader_arr[0].Name,
sizeof(TSimHeader_arr[0].Name));
memcpy(pflight_data->unit, TSimHeader_arr[0].Unit,
sizeof(TSimHeader_arr[0].Unit));
memcpy(pflight_data->min, TSimHeader_arr[0].Min,
sizeof(TSimHeader_arr[0].Min));
memcpy(pflight_data->max, TSimHeader_arr[0].Max,
sizeof(TSimHeader_arr[0].Max));
}
if(!firstTime1){
memcpy(pflight_data->value, TSimSignal_arr[0].Value,
sizeof(TSimSignal_arr[0].Value));
}
}
Then I call the writeData() function from another class that writes teh data in the copied arrays to a file.
Here is the writeData()
void LogData::writeData(){
Sleep(350);
int count;
if(firstTime){
fout<<"flight_data,";
for(int i=0; i<RFMAccess::TSimHeader_arr[0].SignalCount; i++){
if(passes == 1){
if(i == 0){
fout<<aflight_data->name[i]<<endl;
passes++;
writeData();
}
else
fout<<aflight_data->name[i]<<",";
}
else if(passes == 2){
if(i == 0){
fout<<aflight_data->unit[i]<<endl;
passes++;
writeData();
}
else
fout<<aflight_data->unit[i]<<",";
}
else if(passes == 3){
if(i == 0){
fout<<aflight_data->min[i]<<endl;
passes++;
writeData();
}
else
fout<<aflight_data->min[i]<<",";
}
else if(passes == 4){
if(i == 0){
fout<<aflight_data->max[i]<<endl;
firstTime = false;
writeData();
}
else
fout<<aflight_data->max[i]<<",";
}
}
}
if(!firstTime && (aflight_data->log == true)){
for(int j=0; j<RFMAccess::TSimHeader_arr[0].SignalCount; j++){
if(j == 0){
fout<<aflight_data->value[j]<<endl;
writeData();
}
else
fout<<aflight_data->value[j]<<",";
}
}
}
Sorry fo rall the code snips, I just wanted to make sure that the problem was understood.
Thanks for the intrest,
Steven
|
|
|
|
|
are you sure you're including string.h in the file that uses memcpy? that error you're getting means it can't find the memcpy function at all.
|
|
|
|
|
Yes it is definetly in there.
The program will compile but, if I run the debugger on the memcpy() function it reads that the function is undefined.
Strange.
Steven
|
|
|
|
|
well you can try a double for loop to copy the data.
for(int i=0; i<47; i++)
for(int j=0; j<20; j++)
old[i][j] = new[i][j];
i wouldn't recomend that (memcpy should work) but at least you can get your debugger going again to examine the memory. if it still crashes then you have some other problem =/
|
|
|
|
|
johnstonsk wrote:
I run the debugger on the memcpy() function it reads that the function is undefined.
What do you mean it is undefined?? If it compiled then it is defined... You mean that the debugger will not step into the memcpy() function? If so you do not have the correct symbols installed..
John
|
|
|
|
|
johnstonsk wrote:
How can I copy a 2dim array?
CIS101 [Introduction to Computer Science]
|
|
|
|
|
Just wanted to extend to all members a hello and to let you know that I am working with MS VC++ 6.0. I have written a database application for my wife's orchid hobby in MS BV 6.0 and hope to duplicate that effort - as I said, I'm new to c++ and to this board. Hello, and I'm looking forward to learning from all of you. Until I'm more comfortable - I will lurk...;)
Paul
|
|
|
|
|
|
Ryan Binns wrote:
we're a pretty nice bunch of people usually
Yes, as long as you don't ask Programming questions in the Lounge or submit an article that it looks like a four year old wrote you should be ok...
John
|
|
|
|
|
John M. Drescher wrote:
Yes, as long as you don't ask Programming questions in the Lounge or submit an article that it looks like a four year old wrote you should be ok...
Exactly
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
Paul Southwick wrote:
in MS BV 6.0
That's the new MS Bisual Vasic programming language that just came out, right?
Seriously though, welcome to CP !
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
I have a number a different arrays.
double t1[10];
char t2[10];
...
double cpT1[10];
char cpT2[10];
If I make a array of the same size to copy into can I use the memcpy() function like this?
memcpy(cpT1, t1, sizeof(t1));
memcpy(cpT2, t2, sizeof(t2));
Or should I create a function that I pass the amount to the memcpy() function?
If So how can I make it so that I can pass any array to the function?
Thanks,
steven
|
|
|
|
|
If the array are statically created (like in your example), that will work, otherwise not !
|
|
|
|
|
|
memcpy(cpT1, t1, sizeof(t1));
memcpy(cpT2, t2, sizeof(t2));
This will work fine.
John
|
|
|
|
|
|
Hi all
Can i get some way to retrieving pointer on member function of my class i.e. make like this
<br />
class A{<br />
void Fun(){<br />
void *pF = &this->Fun;<br />
}<br />
}<br />
By compiled this snippet, compiler complain:
illegal operation on bound member function expression
Whether exit way what i can do it???
Thanks
Sorry for bad eanglish
|
|
|
|
|
Do you mean, 'how can I get something which represents the combination of an object and a member function'?
You can do this with the STL using the mem_fun_t template. The language itself does not permit such an operation. The expression this->Fun is considered to be a bound member function - the only thing you can do with such an expression is to use the () operator on it (i.e., call it).
|
|
|
|
|
Thanks for advice but whats a reason which prevent do this???
|
|
|
|
|
You can do this, but the syntax is slightly different:
void (A::*pF)() = A::Fun; You will have to call the function in the context of an object:
A obj;
(pobj.*pF)();
A *pobj = new A;
(pobj->*pF)(); Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi
I apparently cant properly realise you because of code dont
wont work by me.
Please see this code and ask where i wrong :
class A{
void Fun(){}
void CallFun(){
void (A::*pF) () = A::Fun;
}
}
//Linker show error:
error C2440: 'initializing' : cannot convert from 'int' to 'void (__thiscall A::*)(void)'
There are no conversions from integral values to pointer-to-member values
Thanks
|
|
|
|
|
Hi
I apparently cant properly realise you because of code dont
wont work by me.
Please see this code and say where i wrong :
class A{
void Fun(){}
void CallFun(){
void (A::*pF) () = A::Fun;
}
}
//Linker show error:
error C2440: 'initializing' : cannot convert from 'int' to 'void (__thiscall A::*)(void)'
There are no conversions from integral values to pointer-to-member values
Thanks
|
|
|
|
|
Strange... Your code compiled perfectly with my compiler, and so did the code I provided. Instead of assigning A::Fun you can try using just Fun , but it should work anyway.
What version of VC are you using?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|