Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

johnstonsk

@johnstonsk
About
Posts
92
Topics
39
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • reading in a file and storing the words in a char[]
    J johnstonsk

    You are correct but, There are 47 names, units, min, max. At each (ith) position the data is related. If I just run through the loop 10 times then I won't get the rest of the data all put in the correct array within the struct. I have it working with a 2 dimensional array. I have limited memory so I need to really be sparing on memory. So, I really need to store the names and units in a single dimension array I hope all of that made sense. I have a feeling that it won't work. thanks, Steven

    C / C++ / MFC help c++ data-structures

  • reading in a file and storing the words in a char[]
    J johnstonsk

    I am reading in a file and trying to put words read in a char[]. My array in within a struct and the notation is:

    struct TSimHeader
    {
    char Name[47];
    char Unit[47];
    double Min[47];
    double Max[47];
    int SignalCount;
    int SimStatus;
    int simdkid;
    int modmode;
    int write;
    int call;
    }static TSimHeader_arr[10];

    This is where I read in the file and try to put the values in the appropiate containers:

    string name, unit,min,max,value;

    	for(int i=0; i<47; i++){
    		getline(fin, name, ',');
    		
    		if(name == "STOP")
    			break;
    		getline(fin, unit, ',');
    		getline(fin, min, ',');
    		getline(fin, max, ',');
    		getline(fin, value);
    		
    	   	strcpy(TSimHeader\_arr\[0\].Name\[i\], name.c\_str());
    		strcpy(TSimHeader\_arr\[0\].Unit\[i\], unit.c\_str());
    		
    		//TSimHeader\_arr\[0\].Name\[i\]  =  name;
    		//strcpy(TSimHeader\_arr\[0\].Name, name.c\_str());
    		
    		TSimHeader\_arr\[0\].Min\[i\]   =  atof(min.c\_str());
    		TSimHeader\_arr\[0\].Max\[i\]   =  atof(max.c\_str());
    	        TSimSignal\_arr\[0\].Value\[i\] =  atof(value.c\_str());
    		
    		sig\_count ++;
    

    }

    The error I get is: :*.cpp(104) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast Thanks for the help, Steven

    C / C++ / MFC help c++ data-structures

  • copy a 2 dimensional array
    J johnstonsk

    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

    C / C++ / MFC question data-structures

  • copy a 2 dimensional array
    J johnstonsk

    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]<

    C / C++ / MFC question data-structures

  • copy a 2 dimensional array
    J johnstonsk

    Thanks, I must be doing something ese wrong, because it keeps crashing. I'll keep pecking :) sj

    C / C++ / MFC question data-structures

  • copy a 2 dimensional array
    J johnstonsk

    Static. sj

    C / C++ / MFC question data-structures

  • copy a 2 dimensional array
    J johnstonsk

    How can I copy a 2dim array? thanks, Steven

    C / C++ / MFC question data-structures

  • simple memcpy() question
    J johnstonsk

    thanks, sj

    C / C++ / MFC question data-structures

  • simple memcpy() question
    J johnstonsk

    thanks, sj

    C / C++ / MFC question data-structures

  • simple memcpy() question
    J johnstonsk

    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)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.

    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

    C / C++ / MFC question data-structures

  • How to make a function that you can pass any type of array to??
    J johnstonsk

    thanks steven

    C / C++ / MFC data-structures tutorial question

  • How to make a function that you can pass any type of array to??
    J johnstonsk

    I think my last post wasn't understandable. I am trying to create a function that can accept any type of an array as a paramater. char[] or double[] or int[] etc. wouldn't it be myFunction(void *data){ do stuff } char tmp[100]; myFunction(tmp); I hope this makes sense. Steven

    C / C++ / MFC data-structures tutorial question

  • function that doesn't care about the type in the paramater??
    J johnstonsk

    It's saying that the type of void is unknown or zero. thanks steven

    C / C++ / MFC data-structures help question

  • function that doesn't care about the type in the paramater??
    J johnstonsk

    Sorry the subject was hard to summerize. I have created a function that I thought was type independent, meaning that it didn't matter what type of an array was passed to the function. It would just write the data with a comma seperation. I have 2 structure in a class called RFMAccess:

    struct TSimHeader
    {
    char Name[47][21];
    char Unit[47][21];
    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\];
    

    The data in these structures gets updated 2x a second. I also want to write the data to a file 2x a second so, I created a function that I thought would do this without having to declare the array type. I want to be able to use this later in other projects. Here is my function. I am doing something incorrect here, but just not sure what it is.

    ofstream fout ("test.txt");
    bool firstTime = true;
    int passes = 1;

    void LogData::writeData(void *data){
    int count;
    if(firstTime){
    fout<<"flight_data,";
    for(int i=0; i<RFMAccess::TSimHeader_arr[0].SignalCount; i++){
    if(i == 0){
    fout<log == true)){
    if(i == 0){
    fout<<data[i]<

    Thnaks for the help,
    Steven

    C / C++ / MFC data-structures help question

  • Getting the same value everytime??
    J johnstonsk

    I am trying to spin through an array in a struct and for each element in that array I want to get the value of another array in another struct. The problem I am having is that the value is always the same. My structs are: struct TSimHeader { char Name[45][20]; char Unit[45][20]; double Min[45]; double Max[45]; int SignalCount; int SimStatus; }static TSimHeader_arr[10]; struct TSimSignal { double Value[45]; double TimeStamp; }static TSimSignal_arr[10]; My function to match elements in the TSimHeader_arr[0].Name[] array with the same element in the TSimSignal_arr[0].Value[] is: **void Tflight_data::getValues(){ int numSignals = RFMAccess::TSimHeader_arr[0].SignalCount; for(int i=0; i<numSignals; i++){ char* temp = RFMAccess::TSimHeader_arr[0].Name[i]; char* temp2 = RFMAccess::TSimHeader_arr[0].Name[i+1]; if(strcmp(temp, "pla")) display_pla_level(RFMAccess::TSimSignal_arr[0].Value[i]); if(strcmp(temp, "pitch_stickF")&& strcmp(temp2, "roll_stickF")){ roll = (RFMAccess::TSimSignal_arr[0].Value[i] / 10.0); pitch = (RFMAccess::TSimSignal_arr[0].Value[i+1] / 10.0); flight_data->fwd_pl->Repaint(); } if(strcmp(temp, "nose_wow")){ if(RFMAccess::TSimSignal_arr[0].Value[i] != 0) front_wheel_led->Active = true; } if(strcmp(temp, "left_wow")){ if(RFMAccess::TSimSignal_arr[0].Value[i] != 0) left_wheel_led->Active = true; } if(strcmp(temp, "right_wow")){ if(RFMAccess::TSimSignal_arr[0].Value[i] != 0) right_wheel_led->Active = true; } if(strcmp(temp, "pitch_trim")) pitch_data_lb->Caption = (AnsiString)RFMAccess::TSimSignal_arr[0].Value[i]; if(strcmp(temp, "roll_trim")) roll_data_lb->Caption = (AnsiString)RFMAccess::TSimSignal_arr[0].Value[i]; if(strcmp(temp, "yaw_trim")) yaw_data_lb->Caption = (AnsiString)RFMAccess::TSimSignal_arr[0].Value[i]; } }** The values should be different depending on the word in the char array. It should match with the exact element in the Values array. Any ideas why I am getting the same value on each if statement? I hope I explained it well enough. Thanks, steven:)

    C / C++ / MFC data-structures regex help question

  • Is there any way to get this to work CString???
    J johnstonsk

    Yes, I have a PCI card with a gig of memory that is shared with 5 other machines. Some of the words are longer than others so, if I just make the 2nd dimension the size of the longest word will I have any problems reading them on the other side of the network? thanks, Steven

    C / C++ / MFC help graphics data-structures business question

  • Is there any way to get this to work CString???
    J johnstonsk

    Ryan, That makes sense. Which would take up less space an array of char Names[45][10] or string[45]? I am trying to use the least amount of space. Thanks, Steven

    C / C++ / MFC help graphics data-structures business question

  • Is there any way to get this to work CString???
    J johnstonsk

    You are right it was only printing ouot 1 character. But, if later on I need to access the array of names and get Names[15] how can I do that? I just tried to print out TSimHeader_arr[0].Names[15] and it printed out Are the words getting put in the char Names[]? Sorry, but I just don't quite understand. Thanks, Steven

    C / C++ / MFC help graphics data-structures business question

  • Is there any way to get this to work CString???
    J johnstonsk

    I know I have been stuck on the same problem for the last few days but, I have to get this to work or my rpogram won't function correctly. Like I need it to. I am using the getline() function to read in a file. I need to put the first word on each line in a char array. string name, unit,min,max,value; for(int i=0; i<45; i++){ getline(fin, name, ','); if(name == "STOP") break; getline(fin, unit, ','); getline(fin, min, ','); getline(fin, max, ','); getline(fin, value); cout< All of the above are ways that I have tried. I don't get the correct word put in the char array. I know the words are getting read in from the file correctly. They are just not getting put in the char[] correctly. Is there another way that I could go about doing this? Is this the best wat to read in a file and put the words in a char[]? I have to use a char[] because of certain requirements that my boss has given me. I would love to use a vector, but it won't work Thanks for your help, Steven

    C / C++ / MFC help graphics data-structures business question

  • CString questions
    J johnstonsk

    I posted them in a reply above this one. Thanks Ryan, Steven

    C / C++ / MFC question data-structures
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups