Re: Pointers Problem



Hi Manoj,

on Sat, 17 Jan 2004, Manoj tr wrote:

hai all

  char **argv;   
  char *line1="Good Morning";
  char *line2="Good Evening";
 
 how to copy line1 to the first index of argv and line2 to the second. 
ie argv[0], argv[1];
 and how to retrive this line1 and line2 

You do it the same way as with arrays in general (char** is just a pointer to
a pointer of the type char).

char **argv = malloc (sizeof (char *) * amount_of_elements);
if (argv != NULL)
  {
     argv[0] = malloc (strlen (line1) + 1);
     if (argv[0] != NULL)
       strncpy (argv[0], line1, strlen (line1) + 1); /* NUL terminate! */
...
  }

If you are working with the glib, refer to the proper glib replacements for
malloc and so on.

Regards
Marcus

-- 
We don't understand the software, and sometimes we don't understand the 
hardware, but we can *see* the blinking lights!

Attachment: pgpx5HbLsjZWn.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]