Re: char * and char []

From: Pink Floyd (floyd@south.mit.edu)
Date: 11/30/95


   This is what I got:
   char command[MAX_INPUT_LENGTH]
   char *cmdd;

   I wanna make cmdd = command so I can process the cmdd variable in exactly
   the same way perform_act does (looking for $? strings, like $n and $N). The
   problem is, like I said before... the way perform_act does it, it needs a
   char *, but the string I want to process is in the variable[xx] format. Is
   there a way to converty one from the other? 

cmdd = command;

   If I used strcpy or even
   sprintf(cmdd, "%s", command) it crashes the first time I try to use the cmdd
   variable in any way.

The way you've done it here, cmdd is only a pointer, it is not pointing to 
any memory.  You're writing to wherever cmdd happened to be pointing when
initialized, which is undefined.
Remember, the name of an array with no subscript is a pointer to the first
element of that array..  i.e., command == &command[0].

Does this help?



This archive was generated by hypermail 2b30 : 12/07/00 PST