Hello there, internet is full of these questions but any of them seems to fit my problem.
It's been a week since I started programming again, being busy with other university stuffs. So I will really appreciate your help.
Anyway, I'll write a pair of lines to illustrate you the quandary:
Let's think I've inizialized those two elements:
1 2 3
|
char array[15] = "words and 1" //smth like "abc 1"; [15] is purely academic
char* ptr = array;
|
My aim is to convert that "
1" at the end of the array with another
number, so that it would print "words and 2" or else. I need to change that final number because I have a function that prints a graph and TCanvas (from ROOT reference) has as input variables a char* (which actually defines the name of the graph), but being this function inside a do-while loop, I can't directly call the function and insert the
char* I want.
As example I tried the following lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
int n = 5;
if( char b = static_cast<char>(n) )
array[10] = n;
//or else
int n = 5;
if( char b = static_cast<char>(n) )
ptr[10] = n;
//or else
int n = 5;
if( char* b = static_cast<char*>(n) )
ptr[10] = n;
|
using usual casting:
1 2 3 4 5 6 7
|
int n = 5;
char b = (char)n;
array[10] = b;
|
I've tried also with
dynaimc_cast, if you need to know.
Nothing seems to work as it should, printng wierd symbols instead of the declared number.
I'm asking you to make me clear those passages and give me some references to look over, maybe I'm just confuse how to use properly these tools.
Thanks for the support.