tags:

views:

118

answers:

2

If I have a function that returns a (char) in c and I have a (char* getSomething) how do I cast it? It is giving me an error when I try to cast it through either (char*) or (char*)&

Example: If the function is :

char* getSomething;
getSomething = getSth(var);

getSth return a char

A: 
*getSomething = getSth(var);

Basically it says "put the char where getSomething points to..."

Mike Gleason jr Couturier
You'll want to allocate memory for that pointer before you store a char to it. Point it at some other char, or use malloc to allocate memory from the heap.
Harold L
A good reminder! I assumed the memory was allocated because I didn't saw no #include either ;)
Mike Gleason jr Couturier
+3  A: 
rzrgenesys187
when i do print getSomething it adds a char. For example if something was (e) it will tell me getSomething is (ed)
When you print make sure you are dereferencing the pointer, *getSomething: printf("%c\n", *getSomething); otherwise, it will print a byte of the memory address where the data is stored
rzrgenesys187