include stdlib include glib int main int argc char argv int GPtrArray

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdlib.h>
#include <glib.h>
int main(int argc, char **argv)
{
int i;
GPtrArray *array = g_ptr_array_new();
gchar **strings;
char *result;
for (i = 0; i < argc; i++)
g_ptr_array_add(array, argv[i]);
/* NEVER FORGET THAT! */
g_ptr_array_add(array, NULL);
strings = (gchar **)g_ptr_array_free(array, FALSE);
p = g_strjoinv(" ", strings);
/*
* BEWARE here: if your GPtrArray contains elements of dynamically allocated strings,
* then you should use g_strfreev(). BUT if the pointers contain only statically
* allocated strings, you MUST use g_free().
*/
g_free(strings);
g_fprintf(stderr, "My command line was: \"%s\"\n", p);
g_free(p);
exit(0);
}