Tuesday 12 February 2013

String - Based Input - Output Functions - C Programming Language


The functions getc(), getchar(), putc() and putchar() perform character-based input-output. C language provides the functions gets() and puts() for string-based input-output as shown in the following program:

#include <stdio.h>

main()
{
char in_str[21];
puts("Enter a String of max 20 characters");
gets(in_str);
fflush(stdin);
puts(in_str);
}

It is a good programming pracice to prompt for input by displaying a message before an input. This has been done using the puts() function in this program.

The function puts() accepts, as parameter, a string variable or a string constant for display on the standard output. The puts() function causes the cursor to jump to the next line after printing the string. The function gets() accepts the string variable into the location where the input string is to be stored.

0 comments:

Post a Comment

Powered by Blogger.