2022-06-24 02:43:47 +00:00
|
|
|
|
2022-07-23 21:58:09 +00:00
|
|
|
#include <ctype.h>
|
2022-06-24 02:43:47 +00:00
|
|
|
#include <stdio.h>
|
2022-07-23 21:58:09 +00:00
|
|
|
|
|
|
|
void demo_scanf(const char* fmt, FILE* s)
|
|
|
|
{
|
|
|
|
while (*fmt != '\0') {
|
|
|
|
if (*fmt == '%') {
|
|
|
|
int c;
|
|
|
|
switch (*++fmt) {
|
|
|
|
case 'u':
|
|
|
|
while (isspace(c=getc(s))) {}
|
|
|
|
unsigned int num = 0;
|
|
|
|
while (isdigit(c)) {
|
|
|
|
num = num*10 + c-'0';
|
|
|
|
c = getc(s);
|
|
|
|
}
|
|
|
|
printf("%%u scanned %u\n", num);
|
|
|
|
ungetc(c, s);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
c = getc(s);
|
|
|
|
printf("%%c scanned '%c'\n", c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++fmt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
printf("Please enter a string: ");
|
|
|
|
fflush(stdout);
|
|
|
|
demo_scanf("%u%c", stdin);
|
2022-06-24 02:43:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|