String Input form User in C

String input in C programming is used to take string input from the user, scanf() is one of the commonly used function to take string input from the user.

Program Printing Keyboard Entered Key Code

In the following program user enter character will save in the i, and print i value in Digits on the output screen.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
char i;
printf("Enter any character: ");
scanf("%c", &i);
printf("Entered character is: %d", i);
getch();
}
Output
Enter any character: F
Entered character is: 70

Program Printing String Value

In the following program value assigned and stored in str, and printing on the output screen.
string library will be need to include for working with String.

Program

#include<stdio.h>
#include<conio.h>
#include<string>
void main()
{
string str;
str = "Bilal Khan";
printf("%s", str);
getch();
}
Output
Bilal Khan

Program User Enter String Value Printing

In the following program user entered value will be stored in str, and printing on the output screen.
string library will be need to include for working with String.

Program

#include<stdio.h>
#include<conio.h>
#include<string>
void main()
{
string str;
printf("Enter Ur Name: ");
scanf("%s", str);
printf("Ur Name is: %s", str);
getch();
}
Output
Enter Ur Name: Bilal Khan
Ur Name is: Bilal

Program Assigning Values to Variables and Printing

In the following program assigning int, float, double, and char values to variables and printing on the output screen.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int integerVar = 100;
float floatingVar = 331.79;
double doubleVar = 8.44e+11;
char charVar = 'W';
printf("integerVar = %i\n", integerVar);
printf("floatingVar = %f\n", floatingVar);
printf("doubleVar = %e\n", doubleVar);
printf("doubleVar = %g\n", doubleVar);
printf("charVar = %c\n", charVar);
getch();
}
Output
integerVar = 100
floatingVar = 331.790009
doubleVar = 8.440000e+11
doubleVar = 8.44e+11
charVar = W