Home / Programs / scanf() to read a string
Programming Example

scanf() to read a string

👁 986 Views
💻 Practical Program
📘 Step by Step Learning
This C program illustrates how to read string from terminal.

Program Code

/* 
 
Author: Atnyla Developer

*/

#include<stdio.h>
int main()
{
    char name[20];
    printf("Enter Your name: ");
    scanf("%s", name);
    printf("Your name is %s.", name);
    return 0;
}

Output

Enter Your name: Rambo Azmi
Your name is Rambo. 

Explanation

This C program illustrates how to read string from terminal.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.