copy a 2 dimensional array
-
How can I copy a 2dim array? thanks, Steven
-
How can I copy a 2dim array? thanks, Steven
Dynamic or Static?? John
-
Dynamic or Static?? John
Static. sj
-
Static. sj
I believe you can use memcpy in the same way you did as a 1 dimensional array. John
-
How can I copy a 2dim array? thanks, Steven
If it's the same as in your previous question, but in two dimensions, then you can do the same thing
char a1[10][10];
char a2[10][10];
memcpy(a1, a2, sizeof(a2));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"
-
If it's the same as in your previous question, but in two dimensions, then you can do the same thing
char a1[10][10];
char a2[10][10];
memcpy(a1, a2, sizeof(a2));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"
Thanks, I must be doing something ese wrong, because it keeps crashing. I'll keep pecking :) sj
-
Thanks, I must be doing something ese wrong, because it keeps crashing. I'll keep pecking :) sj
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"
-
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; iname[i]< -
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; iname[i]< -
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
-
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 =/
-
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
johnstonsk wrote: I run the debugger on the memcpy() function it reads that the function is undefined. :confused::confused::confused: 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
-
How can I copy a 2dim array? thanks, Steven