Table of Contents
C Program to Print a String Entered by the User
#include <stdio.h>
int main()
{
char name[20]; // Character array
printf("\n\tC Program to Print a string");
printf("\n\tEnter a string to print\n\t");
scanf("%s",name);
printf("\tEntered string is: %s\n\n", name);
return 0;
}
Output
Code Explanation
First, declare a string type variable. Then using printf() function print “Enter a string to print”. Then using scanf() function read the string inputted by the user and store it in the variable previously declared. Then print the string using printf() function.
People Also Ask
How strings are read and printed?
First take a string as input from the user by scanf() function and store it in a character array. Then using printf() function print the string on console.