Can someone please explain me the use of .%[0-9]
in the above statement.
This is the problem statement:
The first line of input is an integer N. This is followed by N lines, each starting with the character ‘0’, followed by a dot ‘.’, then followed by an unknown number of digits (up to 100 digits), and finally terminated with three dots ‘...’.
#include <cstdio>
using namespace std;
int N;
char x[110];
int main() {
scanf("%d\n", &N);
while (N--) { // we simply loop from N, N-1, N-2, ..., 0
scanf("0.%[0-9]...\n", &x); // ‘&’ is optional when x is a char array
printf("the digits are 0.%s\n", x);
} } // return 0;
Input for the code:-
3
0.1227...
0.517611738...
0.7341231223444344389923899277...
Output for the code:-
the digits are 0.1227
the digits are 0.517611738
the digits are 0.7341231223444344389923899277