All articles
c

A program to read a STRING and print it

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 065

The following code shows how to write a program to read a STRING and print it.

Program

#include <stdio.h>
 
void main()
{
    char str[30];
 
    printf("Enter a string: ");
    gets(str);
 
    printf("str = %s", str);
 
    printf("\n");
}

Result

Enter a string: hello world
str = hello world

Comments