what function will convert a char to its number value
-
Believe me I don't have to do this for a school project. I have created a tool that display flight simulator data in real time. Long story short: (this is just another feature of the program) The flight simulator writes to a file and I use the getline() function to get the names of signals that the sim wrote and put them in
TSimHeader_arr[0].Name[i]
which is an array in a struct. anyways I think the function(char)strdup(name.c_str())
isn't putting them in the char array correctly. Because when I read them bach out they are strange characters. I don't know how to do this. Does anyone??? stevenvoid setInitialValues(){ sSignal.SimWriteFlag=1; sSignal.DisplayReadFlag=0; sHeader.SimStatus=setSimStatus(); string name,unit,min,max,value; for(int i=0; iTSimHeader_arr[0].Name[i] = (char)strdup(name.c_str()); TSimHeader_arr[0].Unit[i] = (char)strdup(unit.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()); // printf("%s",TSimHeader_arr[0].Name[sig_count]); sig_count ++; } TSimHeader_arr[0].SignalCount = sig_count; writeRfmData(); createRandNum(); }
Prototype: char *_strdup( const char *strSource ); Bad: (char)strdup(name.c_str()); // this is incorrect usage Good: strdup(name.c_str()); // normal usage Ok: (char*)strdup(name.c_str()); // this is redundant INTP