home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!newshub.ccs.yorku.ca!yetti!g-yao
- From: g-yao@cs.yorku.ca (Ling Yao)
- Newsgroups: comp.lang.c
- Subject: Help to solve problem with "gets()"
- Message-ID: <1429@yetti.UUCP>
- Date: 10 Sep 92 19:02:04 GMT
- Article-I.D.: yetti.1429
- Sender: news@yetti.UUCP
- Distribution: world
- Organization: York University, Dept. of Computer Science
- Lines: 91
-
- Hi, Dear friends:
-
- As a "C" novice, I would like to ask some advice about how to use
- gets().
-
- The following is my programm:
-
- *************************************************************************
- #include <stdio.h>
-
- static char *message[]={"Translation:",
- "0. X 1. Y 2. Z",
- "Exit:",
- "x or X",
- NULL
- };
- main()
- {
- float tmp;
- int i=0;
- char *a;
-
- /* print input message */
- while(*message[i]!=NULL)
- {
- printf("%s\n",message[i]);
- i++;
- }
-
- L1: gets(a);
- printf("gets=%s\n",a);
-
- switch(*a) {
- case '0': printf("translate in x ");
- return(1);
-
- case '1': printf("translate in y ");
- return(1);
-
- case '2': printf("translate in z");
- return(1);
-
- case 'x':
- case 'X':
- return(0);
-
-
- default:
- goto L1;
- }
- }
- **************************************************************************
-
- When I run it , I get following result:
-
- ----------------------------------
- Translation:
- 0. X 1. Y 2. Z
- Exit:
- x or X
- Segmentation fault (core dumped)
- _________________________________
-
- When I use lint, it showed:
-
- ____________________________________
- gets() returns value always ignore.
- ------------------------------------
-
- Some friends who can kindly give me some help ,
- I would it appreciate very much.
-
- Please answer this by email , if it is convience to you.
-
- Thanks in advance.
-
-
- +-------------------------------------------------------------+
- | Ling YAO "I die when it's time for |
- | Department of Computer Science me to die. So let me live |
- | York University my life the way I want to."|
- | North York, Ont. Canada M3J 1P3 -----Jimi Hendrix |
- | e-mail: g-yao@cs.yorku.ca |
- | Office phone:(416)736-2100 home phone:(416)650-1480 |
- | Ext.20242 or 20275 Fax: (416)650-1480 |
- +-------------------------------------------------------------+
- --
-
- +-------------------------------------------------------------+
- | Ling YAO "I die when it's time for |
- | Department of Computer Science me to die. So let me live |
-