![](/img/trans.png)
[英]Learning how to properly reference to a struct field when using scanf (C)
[英]using scanf with a struct passed by reference
我正在傳遞一個 struct info 函數,在該函數中我使用 scanf() 將輸入值分配給結構的內部變量。 內部變量是一個unsigned int
。
當我使用: scanf("%u",s->member)
或scanf("%u",(*s).member)
我收到警告:
windows.c:62:36: 警告: 格式指定類型 'unsigned int *' 但參數的類型為 'unsigned int' [-Wformat]
運行時出現段錯誤。
如果我使用s.member
或(&s).member
我會收到編譯器錯誤。
因為我試圖訪問結構內部變量,所以我需要做一些不同的事情嗎?
我知道 scanf() 顯然存在問題,所以有些人說要使用 fgets(),這是 scanf() 的問題嗎?
解決了,我需要使用
scanf("%u", &s->member);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.