roth@ips.ethz.ch (Martin Roth) (06/28/90)
Does anyone know, how I can use NeWS dialog boxes from a C programm in a simple way ? I just search for a routine with opens up a notifier window, displays a prompt ("Please enter a string:") and lets the user type a line of text. After RETURN (or an ACCEPT-Button), the routine should return and pass the string to my C program. A call like ask_text("Enter your Name:", string); shold create a window like +----------------------+ | Enter your Name: | | | | ___________________ | | | +----------------------+ and pass the input back in string. It doesn't matter how it looks, if it has an ACCEPT button or not, I just want a better way to read strings from the user than with scanf from the tty window. Thanks in advance. Martin Roth, Interdisciplinary Project Center Supercomputing, Graphics Laboratory, ETH Zurich, Switzerland roth @ ips.ethz.ch
gavin@krypton.sgi.com (Gavin A. Bell) (06/29/90)
In article <204:roth@ips.ethz.ch> roth@ips.ethz.ch (Martin Roth) writes: >A call like ask_text("Enter your Name:", string); >shold create a window like > +----------------------+ > | Enter your Name: | > | | > | ___________________ | > | | > +----------------------+ >and pass the input back in string. >Martin Roth, Interdisciplinary Project Center Supercomputing, Graphics > Laboratory, ETH Zurich, Switzerland Try the following. It relies on the 'launch' command to do all the dirty work, and is definitely not The Right Way of doing this sort of thing, but it works! Save following in prompt.c, compile with: cc prompt.c -o prompt -lc_s Run it with: ./prompt -----------cut here--------------- /* * Example of how to get a string from the user nicely */ #include <stdio.h> #include <string.h> void GetInputFromUser(char *s, int len_s, const char *m) { char launchline[300]; /* Should dynamically allocate... */ FILE *fp; sprintf(launchline, "launch -h echo -m \"%s\"", m); if ((fp = popen(launchline, "r")) != NULL) { fgets(s, len_s, fp); pclose(fp); /* Strip off trailing newline */ if (s[0] != '\0' && s[strlen(s)-1] == '\n') { s[strlen(s)-1] = '\0'; } } else s[0] = '\0'; } main() { char s[100]; GetInputFromUser(s, 100, "Enter your Name:"); if (s[0] != '\0') fprintf(stderr, "User entered: %s\n", s); else fprintf(stderr, "Nothing entered\n"); } --gavin (gavin@sgi.com, (415)335-1024)