Path: utzoo!utgpu!watserv1!watmath!att!rutgers!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!apple!olivea!mintaka!bloom-beacon!morgan.COM!jordan From: jordan@morgan.COM (Jordan Hayes) Newsgroups: comp.windows.x Subject: Re: motif XmString to char Message-ID: <9010171613.AA23062@s6.Morgan.COM> Date: 17 Oct 90 16:13:40 GMT References: <2863@lamont.ldgo.columbia.edu> Sender: daemon@athena.mit.edu (Mr Background) Organization: Morgan Stanley, & Co., Inc. / New York City, NY Lines: 49 Suzanne O'Hara asks: I am learning to program with motif and have run into what seems a very simple problem. I have not been able to find a way to convert a motif XmString to a regular C char string. This should work: ----- cut here ----- #include char * XmStringGet(w, str) Widget w; /* widget that owns the XmString */ XmString str; /* the XmString itself */ { char *text, *buf; Boolean sep; XmStringContext context; XmStringDirection dir; XmStringCharSet set; if (XmStringInitContext(&context, str) == FALSE) { XtAppWarning(XtWidgetToApplicationContext(w), "couldn't initialize context!\n"); return((char *)NULL); } buf = (char *)NULL; while (XmStringGetNextSegment(context, &text, &set, &dir, &sep)) { if (sep) break; if (text == (char *)NULL || *text == (char)NULL) continue; if (buf) { buf = XtRealloc(buf, strlen(buf) + strlen(text) + 2); (void)strcat(buf, text); } else buf = XtNewString(text); } XmStringFreeContext(context); return(buf); } ----- cut here ----- /jordan