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.
In the following program user enter character will save in the i
, and print i
value in Digits on
the output screen.
#include<stdio.h>
#include<conio.h>
void main()
{
char i;
printf("Enter any character: ");
scanf("%c", &i);
printf("Entered character is: %d", i);
getch();
}
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.
#include<stdio.h>
#include<conio.h>
#include<string>
void main()
{
string str;
str = "Bilal Khan";
printf("%s", str);
getch();
}
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.
#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();
}
In the following program assigning int
, float
,
double
, and char
values to
variables and printing on the output screen.
#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();
}