Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Standard Library function scanf

August 25, 2013 Posted by: GPA Views: 871 0 comments

Function scanf() is a input procedure that reads stdin stream and stores the information in the variables. It can read all the built-in types and automatically convert them to the appropriate internal format. This function has two arguments. The first argument, the format control string, indicates the type of data that should be input by the user. The second argument is  a variable input by the user.

Next  specifier characters are presented in table:

 

Specifier Type Description
%i int Scan an integer as a signed number. Similar to %d, but interprets the number as hexadecimal when preceded by 0x and octal when preceded by 0.
%u unsigned int Scan for decimal unsigned int
%d decimal Scan an integer as a signed decimal number.
%f float Scan a floating-point number. Example 5.99
%c char Scan a character (char). No null character is added. Example 'K'
%s String of characters Scan a string type. Example "Hello"
%o Octal integer Scan a Octal integer type. Example: any number of octal digits (0-7).
%x Hexadecimal integer Scan a Hexadecimal integer type. Example: any number of hexadecimal digits (0-9, a-f, A-F).
%p Pointer address Scan a sequence of characters representing a pointer.
%n Count No input is consumed.The number of characters of the input string is stored in the pointed location.
%lf double Scan as a double floating-point number.
%lf long double Scan as a long double floating-point number

Example:

 

  
  
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
int number1;//first number inputed by user   
int number2;//second number inputed by user
int sum;//sum of two numbers
printf("Enter first number: ");
scanf("%d",&number1);//Read first number
printf("Enter second number: ");
scanf("%d",&number2);//Read second number
//add two numbers
sum=number1+number2;
printf("Sum = %d",sum);//show result
return 0;
}


Output

Standard Library function scanf example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe