summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/gets.c
blob: 0ca38d6342b6eb6762190220c17ca20585370cb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**************************************************************************
 *
 * Purpose: Compare the action of gets and fgets reading data from STDIN.
 * Author:  M J Leslie
 * Date:    22-Apr-95
 *
 *************************************************************************/

#include <stdio.h>

main()
{
  char buff[80];			/* Input buffer.		*/

					/* Get data from the keyboard.	*/
  printf("\nplease enter text => ");

  gets(buff);
  
  printf("\nlength is %d #%s#\n", strlen(buff), buff);

					/* Get data from the keyboard.	*/
  printf("\nplease enter text => ");

  fgets(buff, sizeof(buff), stdin);
  
  printf("\nlength is %d #%s#\n\n",strlen(buff),  buff);
}

/*************************************************************************
 * 
 *  Example program run.
 *  --------------------
 * 
 * please enter text => abcd
 * 
 * length is 4 #abcd# 
 * 
 * please enter text => abcd
 * 
 * length is 5 #abcd
 * #
 *
 *************************************************************************/