Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!swrinde!ucsd!ames!sgi!shinobu!odin!krypton!gavin From: gavin@krypton.sgi.com (Gavin A. Bell) Newsgroups: comp.sys.sgi Subject: Re: How to use dialog boxes ? Message-ID: <9691@odin.corp.sgi.com> Date: 28 Jun 90 18:38:24 GMT References: <204:roth@ips.ethz.ch> Sender: news@odin.corp.sgi.com Lines: 62 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 #include 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)