User Input using Gets and Puts in C

User input using Gets and Puts in C programming is used to take input from the user and print the value. Gets are used to take input from the user, and Puts are used to print the value.

Assigning Word and printing

Program

#include<stdio.h>
#include<conio.h>
void main()
{
char c[] = "HiLaLs Afridi"; //assigning value to array.
printf("%s", c); //and printing.
getch();
}
//U also write like 'char c[13] = "HiLaLs Afridi";'.
Output
HiLaLs Afridi

Assigning Word and Printing Another Method

Program

#include<stdio.h>
#include<conio.h>
void main()
{
char name[] = "HiLaLs Afridi"; //assigning name to 'name' Array.
int i = 0;
while(name[i] != '\0') //loop looping if Array Not equal to 0.
{
printf("%c", name[i]); //and printing Elements of 'name' Array.
i++;
}
getch();
}
Output
HiLaLs Afridi

Program User Entering Value and Printing

Program

#include<stdio.h>
#include<conio.h>
void main()
{
char c[10]; //this is array.
printf("Please Enter Ur Name: ");
scanf("%s", &c); //user enter value storing in 'c' array.
printf("Ur Name is: ");
printf("%s", c); //and printing.
getch();
}
Output
Please Enter Ur Name: Bilal
Ur Name is: Bilal

Program User Entering Name and Printing Using Gets and Puts
Program

#include<stdio.h>
#include<conio.h>
void main()
{
char c[20]; //this is array.
puts("Please Enter Ur Full Name: ");
gets(c); //user enter value storing in 'c' array.
puts("Ur Name is: ");
puts(c); //and printing.
getch();
}
Output
Please Enter Ur Full Name:
Bilal Khan
Ur Name is:
Bilal Khan