View Single Post
Old Feb 23rd, 2008, 7:33 PM   #3
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 94
Rep Power: 1 null_ptr0 is on a distinguished road
Re: from void * to C string?

Quote:
Originally Posted by Sane View Post
Here it is in C. I'm not sure if C++ has different rules regarding void pointer typecasting, but hopefully it can be of use until someone else fills in the details for me.

C Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void outstring(void *p) {
  5. char *s = (char *)p;
  6. printf("%s\n", s);
  7. }
  8.  
  9. int main() {
  10. outstring("Hello World!");
  11. return 0;
  12. }
fixed that with a dumb fix: i was suppose to use static_cast. new error now.
null_ptr0 is offline   Reply With Quote