преобразование входного формата (input format conversion)
Примеры (Examples)
To use the dynamic allocation conversion specifier, specify m
as
a length modifier (thus %ms
or %m[
range]
). The caller must
free(3) the returned string, as in the following example:
char *p;
int n;
errno = 0;
n = scanf("%m[a-z]", &p);
if (n == 1) {
printf("read: %s\n", p);
free(p);
} else if (errno != 0) {
perror("scanf");
} else {
fprintf(stderr, "No matching characters\n");
}
As shown in the above example, it is necessary to call free(3)
only if the scanf
() call successfully read a string.