I want to have a constant character array of which each array element to be passed to function in runtime. I have written them in following way:
const char *IntenistyVal[] ={"1","2","3","4","5"};
and The function is
Test(const char *pText)
(I cannot change this as this is one of standard Library function). Now when I try to call the function "Test" as
Test(IntensityVal[0])
I also Tried
const char * const IntenistyVal[] ={"1","2","3","4","5"};
In both cases I am getting error as "Expression must have a constant value". Can Any one help me where I am doing Wrong.
A const array of char would be
const char IntensityVal[] ={'1', '2', '3', '4', '5', 0};
The final 0 is important if you want to pass it as a string. But I'm not sure if this is what you really want. It would help if you didn't hide the actual function as Test
, but tell us the actual Standard Library function and what you want to achieve (ie you have an XY-Problem ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.