member) 或 s-6ren">
gpt4 book ai didi

c - 将 scanf 与通过引用传递的结构一起使用

转载 作者:行者123 更新时间:2023-11-30 16:06:20 25 4
gpt4 key购买 nike

我正在向函数传递一个结构信息,在该函数中我使用 scanf() 将输入值分配给该结构的内部变量。内部变量是一个unsigned int

当我使用时:scanf("%u",s->member)scanf("%u",(*s).member) 我收到警告:

windows.c:62:36: warning: format specifies type 'unsigned int *' but the argument has type 'unsigned int' [-Wformat]

当我运行时出现段错误。

如果我使用 s.member(&s).member 我会收到编译器错误。

因为我正在尝试访问结构内部变量,所以我需要做一些不同的事情吗?

我知道 scanf() 显然有问题,所以有人说使用 fgets(),这是 scanf() 的问题吗?

最佳答案

解决了,我需要使用

scanf("%u", &s->member);

关于c - 将 scanf 与通过引用传递的结构一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59996800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com