0
votes

I am passing a struct info a function, and in that function I am using scanf() to assign input values to the inner variables of the struct. The inner variable is an unsigned int.

When I use: scanf("%u",s->member) or scanf("%u",(*s).member) I get a warning:

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

And a seg fault when I run.

If I use s.member or (&s).member I get a compiler error.

Is there something I need to be doing different because I am trying to access a struct inner variable?

I know there are apparently issues with scanf() so some people say to use fgets(), is this an issue of scanf()?

1
Remember, there is no pass-by-reference in C, it is all pass-by-value. To simulate a pass-by-reference, you are simply passing the address-of an object by-value as the parameter. - David C. Rankin

1 Answers

0
votes

Solved, I need to use

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