How to use dialog boxes ?

Gavin A. Bell gavin at krypton.sgi.com
Fri Jun 29 04:38:24 AEST 1990


In article <204:roth at ips.ethz.ch> roth at 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 at sgi.com,  (415)335-1024)



More information about the Comp.sys.sgi mailing list