void* pointers arrggghhh

Started by
10 comments, last by mattd 23 years, 7 months ago
You can use the delete option on when you edit a post

by the way, shouldn''t it be
((conCommand*)(myNode.data))->name = whatever;

I might have exagerated on the ()''s



You know, I never wanted to be a programmer...

Alexandre Moura
Advertisement
An example of how I always do this sort of thing in good old C.
(I even compiled and ran it in VC++ 6.0 as a Win32 console application just to make sure. ) Enjoy.

#include #include typedef struct {    char *name;    int  foo;} myCmnd;typedef struct node{  void        *data;  struct node *next;} myNode;int main(int argc, char* argv[]){  char   str1[10] = "A STRING",         str2[10];  myCmnd cmd;  myNode head1,         *head2 = (myNode *) malloc(sizeof(myNode));  cmd.name = str1;  cmd.foo = 1;  head1.data = (myNode *) &cmd  head2 -> data = (myNode *) &cmd  strcpy(str2, ((myCmnd *)(head1.data)) -> name);  printf("%d %s\n", ((myCmnd *) (head1.data)) -> foo, str2);  strcpy(str2, ((myCmnd *)(head2 -> data)) -> name);  printf("%d %s\n", ((myCmnd *) (head2 -> data)) -> foo, str2);  return 0;} 


Mike Roberts
aka milo
mlbobs@telocity.com

This topic is closed to new replies.

Advertisement