天天看點

Pat出warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_un

計算機程式設計能力考試,輸入要有scanf()的傳回值,雖然沒有什麼卵用,還坑人。

剛送出就出了warning: ignoring return value of ‘int scanf(const char*, …)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n);的錯誤。

有兩個改進辦法:

1.條件句加上判斷,完事兒。

2,直接用(void)在scanf前面。

over~

for(int i=0;i<n;i++){
    if(scanf("%d",&a[i])==1)
        continue;
  }```

           
PAT