What are scanf(“%*s”) and scanf(“%*d”) format identifiers?

前端 未结 5 540
太阳男子
太阳男子 2020-11-30 21:26

What is the practical use of the formats \"%*\" in scanf(). If this format exists, there has to be some purpose behind it. The following program gives weird out

5条回答
  •  情话喂你
    2020-11-30 21:56

    In scanf("%*d",&a) * skips the input. In order to read the inputs one has to use an extra "%d" in scanf. For example:

     int a=1,b=2,c=3;
        scanf("%d %*d %d",&a,&b,&c); //input is given as: 10 20 30
    

    O/p:

    a=10 b=30 and c=3;  // 20 is skipped
    

    If you use another %d i.e: scanf("%d %*d %d %d",&a,&b,&c); //input is given as: 10 20 30 40 then a=10 b=30 c=40.

    If you use "," in scanf then no value will be taken after %*d i.e; scanf("%d %*d,%d" &a,&b,&c)// 10 20 30 O/p: a=10 b=2 c=3 will be the output.

提交回复
热议问题