home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13479 < prev    next >
Encoding:
Text File  |  1992-09-10  |  2.5 KB  |  104 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!newshub.ccs.yorku.ca!yetti!g-yao
  2. From: g-yao@cs.yorku.ca (Ling Yao)
  3. Newsgroups: comp.lang.c
  4. Subject: Help to solve problem with "gets()"
  5. Message-ID: <1429@yetti.UUCP>
  6. Date: 10 Sep 92 19:02:04 GMT
  7. Article-I.D.: yetti.1429
  8. Sender: news@yetti.UUCP
  9. Distribution: world
  10. Organization: York University, Dept. of Computer Science
  11. Lines: 91
  12.  
  13. Hi, Dear friends:
  14.  
  15.    As a "C" novice, I would like to ask some advice about how to use
  16.    gets().
  17.  
  18. The following is my programm:
  19.  
  20. *************************************************************************
  21. #include <stdio.h>
  22.  
  23. static char *message[]={"Translation:",
  24.                 "0. X      1. Y    2. Z",
  25.                         "Exit:",
  26.                 "x or X",
  27.              NULL
  28.                         };
  29. main()
  30. {
  31.     float tmp;
  32.     int i=0;
  33.     char *a;
  34.  
  35. /* print input message */
  36.     while(*message[i]!=NULL)
  37.     {
  38.     printf("%s\n",message[i]);
  39.     i++;
  40.     }
  41.  
  42.    L1: gets(a);
  43.     printf("gets=%s\n",a);
  44.  
  45.     switch(*a) {
  46.     case '0': printf("translate in x ");
  47.             return(1); 
  48.  
  49.     case '1': printf("translate in y ");
  50.             return(1);
  51.  
  52.     case '2': printf("translate in z");
  53.             return(1);
  54.  
  55.     case 'x':
  56.     case 'X':
  57.     return(0);
  58.  
  59.  
  60.     default:
  61.      goto L1;
  62.     }
  63. }
  64. **************************************************************************
  65.  
  66. When I run it , I get following result:
  67.  
  68. ----------------------------------
  69. Translation:
  70. 0. X      1. Y    2. Z
  71. Exit:
  72. x or X
  73. Segmentation fault (core dumped) 
  74. _________________________________
  75.  
  76. When I use lint, it showed:
  77.  
  78. ____________________________________
  79. gets() returns value always ignore.
  80. ------------------------------------
  81.  
  82. Some friends who can kindly give me some help ,
  83. I would it appreciate very much.
  84.  
  85. Please answer this by email , if it is convience to you.
  86.  
  87. Thanks in advance.
  88.  
  89.  
  90. +-------------------------------------------------------------+
  91. | Ling YAO                        "I die when it's time for   |
  92. | Department of Computer Science   me to die. So let me live  |
  93. | York University                  my life the way I want to."|
  94. | North York, Ont. Canada M3J 1P3         -----Jimi Hendrix   | 
  95. | e-mail: g-yao@cs.yorku.ca                                   |
  96. | Office phone:(416)736-2100       home phone:(416)650-1480   |
  97. |        Ext.20242 or 20275        Fax:       (416)650-1480   |
  98. +-------------------------------------------------------------+
  99. -- 
  100.  
  101. +-------------------------------------------------------------+
  102. | Ling YAO                        "I die when it's time for   |
  103. | Department of Computer Science   me to die. So let me live  |
  104.