scanf跳过一个整数读取
int main(){
int a;
scanf("%d %d", &a);//就是我这里只想读取第二个整数,该怎么写
return 0;
} 本帖最后由 jackz007 于 2022-10-12 22:45 编辑
#include <stdio.h>
int main(void)
{
int a ;
scanf("%d%d" , & a , & a) ;
printf("%d\n" , a) ;
scanf("%*d%d" , & a) ;
printf("%d\n" , a) ;
}
编译、运行实况:
D:\\C>x
12 21
21
13 31
31
D:\\C> int main()
{
int a,b;
scanf("%d %d", &a,&b);//就是我这里只想读取第二个整数,该怎么写
return 0;
}
直接属于两个数 中间用空格或者回车都行
int main()
{
int a;
scanf("%*d%d", &a);
return 0;
}
明明有简洁优雅且易读的解决方案(赋值抑制指示符 '*' )
Each conversion specification is introduced by the character %. After the %, the following appear in sequence:
— An optional assignment-suppressing character *.
— An optional decimal integer greater than zero that specifies the maximum field width (in characters).
— An optional length modifier that specifies the size of the receiving object.
— A conversion specifier character that specifies the type of conversion to be applied.
页:
[1]