home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C by Discovery (4th Edition)
/
C_By_Discovery_4th_Edition.tar
/
C_By_Discovery_4th_Edition
/
_DISK_
/
ch5
/
strwarn.c
< prev
next >
Wrap
C/C++ Source or Header
|
2005-06-16
|
858b
|
30 lines
/* strwarn.c
*
* Synopsis - Attempts to accept input of a line of text with
* the library function fgets(). There is an error
* in the program because space for the input line
* was not allocated.
*
* Objective - To point out a common error made by beginning C
* programmers.
*/
/* Include Files */
#include <stdio.h>
/* Constant Definitions */
#define BUFF_SIZE 80
int main( void )
{
char *prompt = "Enter a line of text.\n> ";
char *inputptr, *inputptr1; /* Note 1 */
printf( prompt );
inputptr1 = fgets( inputptr, BUFF_SIZE, stdin ); /* Note 2 */
if ( inputptr1 != NULL )
printf( inputptr1 );
else
printf( "Error in input\n" );
return 0;
}