I have a problem with strncpy. I need to change the first parameter to char for it to compile. I am not sure how I should do it. In C# I can just
int v1 = 123456;
string v2 = "";
v2 = v1.ToString(); // in C# this turns the number 123456 into the string "123456", (maybe itoa?)
Now I can use this v2 variable in a function (strncpy) that has string parameters since v2 is a string. How do I do this in C++?
private:
int pollution_day[Pollution_day_MaxSize];
int pollution_time[Pollution_time_MaxSize];
int pollution_level[Pollution_time_MaxSize];
};
void Pollution::set_pollution_day(int * p_day, int p_day_sz)
{
if ( p_day_sz >= Pollution_day_MaxSize)
p_day_sz = Pollution_day_MaxSize-1;
int * sp_day = p_day;
//trim end
while( isspace(sp_day[p_day_sz-1])) p_day_sz--;
//trim begining
while( isspace(* sp_day))
{
sp_day ++;
p_day_sz--;
}
strncpy (pollution_day, sp_day, p_day_sz); // getting an error here
pollution_day[p_day_sz] = NULL;
return;
};