相关疑难解决方法(0)

什么是scanf("%*s")和scanf("%*d")格式标识符?

"%*"scanf()中格式的实际用途是什么.如果存在这种格式,则必须有一些目的.以下程序给出了奇怪的输出.

#include<stdio.h>
int main()
{
        int i;
        char str[1024];

        printf("Enter text: ");
        scanf("%*s", &str);
        printf("%s\n", str);

        printf("Enter interger: ");
        scanf("%*d", &i);
        printf("%d\n", i);
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

manav@workstation:~$ gcc -Wall -pedantic d.c
d.c: In function ‘main’:
d.c:8: warning: too many arguments for format
d.c:12: warning: too many arguments for format
manav@manav-workstation:~$ ./a.out
Enter text: manav
D
Enter interger: 12345
372
manav@workstation:~$
Run Code Online (Sandbox Code Playgroud)

c formatting scanf

44
推荐指数
4
解决办法
7万
查看次数

scanf()跳过变量

在C中,使用scanf()参数,scanf("%d %*d", &a, &b)行为不同.只为一个变量而不是两个变量输入值!

请解释一下!

scanf("%d %*d", &a, &b);
Run Code Online (Sandbox Code Playgroud)

c scanf

17
推荐指数
2
解决办法
3万
查看次数

scanf()中的%*c - 这是什么意思?

我试图在Turbo C中运行这个程序,但无法破译输出.这%*c是什么意思?任何帮助,将不胜感激.

int dd,mm,yy;
printf("\n\tEnter day,month and year");
scanf("%d %*c %d %*c %d",&dd,&mm,&yy);  // what does %*c mean ?
printf("\n\tThe date is : %d %d %d",dd,mm,yy);
Run Code Online (Sandbox Code Playgroud)

OUTPUT

Enter day, month and year 23
2
1991
3
5
The date is: 23 1991 5
Run Code Online (Sandbox Code Playgroud)

c scanf

3
推荐指数
2
解决办法
9099
查看次数

标签 统计

c ×3

scanf ×3

formatting ×1