August 28th, 2003, 04:17 PM
dereferencing memory in C++
i have a code that returns the memory address to a character array. how do dereference the memory address and print out the character array?
thanks in advance
August 28th, 2003, 04:28 PM
For char* types,
is defined to display the c-string without the need for dereferencing. However, the char array must be terminated with a '\0' for it to be displayed correctly.
Last edited by 7stud; August 28th, 2003 at 04:34 PM.
August 28th, 2003, 04:36 PM
i need to print it out to text file. i am doing this in C. sorry for the confusion.
August 28th, 2003, 04:46 PM
Presuming the char array is null terminated:
fprintf(fout, "%s", chrptr);
where fout is a file handle to the file you want to write with.
If the array is not null terminated (if so, shame on you creating a string without one! everone else behind you will think it has one), then you will either have to stick one on there (be sure there is room!) or (knowing the length of the array) do an fwrite:
fwrite(chrptr, 1, lenofdata, fout);