Friday 3 October 2014

Suppression Character in Scanf()

Suppression Character in Scanf()

If we want to skip any input field then we specify * between the % sign and the conversion specification. The input field is read but its value is not assigned to any address. This character * is called the suppression character. For example-

scanf("%d %*d %d",&a, &b, &c);

Input 

a=25 , b=30 ,c=35

Here 25 is stored in a, 30 skipped and 35 is stored in the b, since no data is available for c so it has garbage value.

scanf("%d %*c %d %*c %d",&d, &m, &y);

Input :

3/1/2003

Here 3 will be stored in d, then / will be skipped , 11 will be stored in m, again / will be skipped and finally 2003 will be stored in y.

#include<stdio.h>
main()
{
int a, b, c;
printf("Enter three number:");
scanf("%d %*d %d",&a,&b,&c);
printf("%d %d %d", a,b,c);
}

Output

Enter three number: 25 ,30 ,35

25  35  25381

the variable c has garbage value.

6 comments:

  1. Hahhah, bhai ne sara c in depth book se copy kar raka h pura

    ReplyDelete
  2. Bro what a big deal it's not compulsory every person have book

    ReplyDelete
  3. lol, @Aman ;-) :-P
    @Unknown It's not a big deal bro. Don't care about what he said.

    ReplyDelete