All articles
c

A program to read a string and print it using gets and puts

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 070

The following code shows how to write a program to read a string and print it using gets() and puts().

Program

#include <stdio.h>
 
void main()
{
    char str[20];
 
    printf("Enter string: ");
    gets(str);
    printf("String is: ");
    puts(str);
 
    printf("\n");
}

Result

Enter string: Hello world!!
String is: Hello world!!

Comments