Reading Input from the Terminal

In C, the scanf() function is used to read input from the terminal. The function is included in the stdio.h header file and has the following syntax:

scanf("format string", &variable1, &variable2, ...);

The format string is a string of characters that specifies the type of input that is expected, and the variables are memory locations where the input values will be stored.

Some common format specifiers that can be used in the format string are:

  • %d: Used for reading integers.
  • %f: Used for reading floating-point numbers.
  • %c: Used for reading characters.
  • %s: Used for reading strings.

Example:

#include <stdio.h>

int main() {
   int age;
   float salary;
   char name[30];
   
   printf("Enter your name: ");
   scanf("%s", name);
   
   printf("Enter your age: ");
   scanf("%d", &age);
   
   printf("Enter your salary: ");
   scanf("%f", &salary);
   
   printf("Name: %s\n", name);
   printf("Age: %d\n", age);
   printf("Salary: %.2f\n", salary);
   
   return 0;
}

When the program is run, it will prompt the user to enter their name, age, and salary. The scanf() function will read the input values and store them in the respective variables. The printf() function is then used to display the input values on the screen.

The scanf() function is an important tool for user input and interaction in a program. It can be used to read values from the user, process the input, and generate appropriate output.

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial
hacklink al dizi film izle film izle yabancı dizi izle fethiye escort bayan escort - vip elit escort erotik film izle hack forum türk ifşa the prepared organik hit hiltonbetbetebetmarsbahishasbetsupertotobetjojobetcasinolevantjojobetjojobet girişjojobetbetebetmarsbahiscasibom adresjojobetjojobetjojobet girişcratosroyalbetcratosroyalbetmarsbahis güncel girişcasibom girişbetciomarsbahis girişbetriyalbaywin girişgrandpashbetCasinoplus girişultrabetjojobet girişcratosslotjojobettümbet girişjojobetcasibomjojobet girişJojobettümbet giriştümbet twitterultrabet girişlunabet girişasyabahiscasibomlunabetvaycasinomegabahismatadorbetbaywinbaywin girişpadişahbetbetorspinpornpoocoinbettilt girişbettilt twittermarsbahisbettilt twitterbettilt girişvaycasinosophie rain leakmegabahis girişsonbahis sonbahis güncelBetwoonBetwoonBetwoon TwitterlunabetLunabetCratosroyalbet