Re: printing the first atom of an t_atomarray [More noob stuff]

You do not have to allocate the t_atom in the heap, you can just use one on the stack.

void moopants(t_atomarray *moo)
{
    t_atom a;
    long k = 0;
    char *p = NULL;

    if (!(atomarray_getindex(moo, 0, &a))
        && !(atom_gettext(1, &a, &k, &p, OBEX_UTIL_ATOM_GETTEXT_DEFAULT))) {
        post("%s", p);
        sysmem_freeptr(p);
    }
}

And to get all atoms.

void moopants(t_atomarray *moo)
{
    long argc, k = 0;
    t_atom *argv = NULL;
    char *p = NULL;

    if (!(atomarray_getatoms(moo, &argc, &argv))
        && !(atom_gettext(argc, argv, &k, &p, OBEX_UTIL_ATOM_GETTEXT_DEFAULT))) {
        post("%s", p);
        sysmem_freeptr(p);
    }
}

HTH.

Attachments:
  1. flop.c
Dec 14, 2012 at 8:00am #236567