I want to create a method that saves any data type in a char array.I already have done the casting stuff..(I finished writing some functions like intToChar() charToInt()..etc.). so wht i want to do now is , create a function like this
1 2 3 4
void saveData(data){
//a some code to identify the data type..
// 'cast' or do something that i prefer to do and save it on an char array which //i have already created...
}
(this "data" parameter should be anykind :P , can it be... )
so my question is how do i retrieve any type of data into this function??
i want to know a way to do this, maybe i should use some other technique...??? can u tell me a technique(a way) to this..?
This is not possible this way. Although it can be done with PODs, this would fail horribly once a class contains pointers (directly or indirectly).
You need to give each of your class a serialize method that writes itself into a stream.
i guess it's impossible to store any type of data in a char type but you can store any type of data in char array and you dont need to get the data type , you just need to know the size of your input data in byte and also you can save your data as string and ofcourse we are talking about only primery type like int ,double,char and...
what exactly you wanna do? give us more detail so we can help you more.
hey ,thank you......
, i want to make a simulation of memory.. by using a linked list... the nodes in the linked list are the memory locations... i took the data part of the node as a structure as shown above, it will contain the datatype, identifier and the value of the variable which is saved in the memory slot/node...
how can i do wht u said? ("store any type of data in char array") i mean , i will also want to store the datatype... how can i identify data type?
if you are able to read the memory you are able to store it in a char array.how do you read a memory block and in what type of variable you store it when you read it.
assume that you read 10 bytes of memory in a buffer it could be an integer ,double or char or whatever...you can read one byte of buffer and save it in value[0] then increment the counter of the array ,read anothe byte of buffer and save it in value[1] and so on.
got it?
this is the algorithm :
1 2 3 4 5 6 7 8 9 10 11 12
void saveData(data){
/*
i=0;
len=data.length;
while (len )
read one byte of data
value[i]=that one byte
i++;
len--;
} // end of while
*/
} //end of saveData