Scanf within printf

-1
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i;
    printf("digite um número %d",scanf("%d",&i));

}

The following program only gives result 1 and I do not understand why.

    
asked by anonymous 14.11.2017 / 18:50

1 answer

2

Because Scanf returns an integer with the number of entries.

scanf("%d",&i) 

This will return the number 1

scanf("%d" "%d",&p,&i) 

You will return the number 2 and so on.

If you put within while , as follows:

while ( scanf("%d", &i) == 1) 

It will be true. If you put

while ( scanf ("%d" "%d", &p, &i) == 2) 

It will be true too.

And so on.

    
25.07.2018 / 01:49