how can i get rid of: warning: value computed is not used [-Wunused-value]

StackOverflow https://stackoverflow.com/questions/20268126

  •  06-08-2022
  •  | 
  •  

Вопрос

I'm a beginner in programming so I would like a simple answer :)

I have a for loop with multiple conditions, which prints out two arrays. It works, but i get a warning and a red line under for(). Why is it so and how can I avoid it? I'm writing it in C and I use a Geany compiler in Ubuntu. :)

for((i=LEN-1) && (j=1); (i>=LEN-3) && (j<=PODIUM); i-- && j++)  
{       
  printf("%d. koht: %s tulemusega %f\n", j, voist[i], tul[i]);      
}
Это было полезно?

Решение

for(i=LEN-1,j=1 ; (i>=LEN-3) && (j<=PODIUM); i--, j++) 

EDIT: It works because this is the correct syntax. you don't need to use and operator to combine two initializations or two increments. you can just use the ,

Другие советы

This warning is because of the return value of (i=LEN-1) && (j=1) which is bot used further.To avoid the warning, try this

int temp;
... 

temp = (i=LEN-1) && (j=1);

for(; (i>=LEN-3) && (j<=PODIUM); i-- && j++)  
{  

     ....

     temp = (i=LEN-1) && (j=1);
} 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top