User input 1234 567
scanf("%2d %2d",&value1,&value2);
scanf("%3d %2d",&value1,&value2);
scanf("%4d %3d",&value1,&value2);
scanf("%-5d",&value1,&value2);
How does all these work actually?? Iam confused..

Have you tried this and seen what it does? That will likely give you a clue.

the number between % and d implies field width i.e. the number of digits to be read from the given input.

In the first statement, scanf("%2d %2d",&value1,&value2);, 12 will be assigned to value1 since field width is 2 and 34 (the unread part will be assigned to value2)

In the second statement, scanf("%3d %2d",&value1,&value2);, 123 will be assigned to value1 and 4 willbe assigned to value2

In the third statement, scanf("%4d %3d",&value1,&value2);, 1234 will be assigned to value1 and 567 will be assigned to value2.

Try the same for the fourth statement of your own.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.