int to char

Hello, I have a problem, I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) ,this is what I have:

1
2
3
4
5
6
7
8
9
char* List::asString(){
    Node* ite = new Node();
    ite= first;//ite is like an iterator of the list
    for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list
            arr[i]=ite->element() ;
            ite= ite->next();
                }
                return arr;
}


But when I print that, I get a bunch of weird symbols...
I need help!!

Thanks!
Last edited on
Can you say what these two stupid statements do?

1
2
Node* ite = new Node();
ite= first;//ite is like an iterator of the list 


What a beautiful way to talk.... they are not stupid, they are necessary.
Node, it's a node which contains an int data, and the next node....
ite is the iterator that goes all through the list.
Last edited on
It seems that you understand nothing and instead to take into account what I said you begin bla..bla..bla.

At first you allocate memory

Node* ite = new Node();

ite contains the address of new object. Then in the next statemenet you overwrite the value pf ite.

ite= first;//ite is like an iterator of the list

So what is the sense of the first statement if the value of ite is overwritten in the second statement?



Last edited on
I got it, thanks, do you know how to convert an int to a char? (whatever the int is)
I do not see where you convert int to char. But in any case you simply can assign an integer value to an object of type char if the value can be represented in char. For example

int x = 0x30;
char c = x;
As for your code then as I have understood you should append your character array with the terminating zero that it can be outputed as a string.
Ok, thanks a lot
Topic archived. No new replies allowed.