[英]My variables aren't working, keep recieving 'expression result unused' error
我目前正在開展一個項目,該項目要求我制作一個右對齊的 # 標記三角形。 我從我的變量“空間”中收到一個錯誤。 有人能告訴我為什么我會收到這個錯誤嗎?
#include <cs50.h>
#include <stdio.h>
int get_height(void);
int lineno;
int column_fill;
int main(void)
{
int height = get_height();
int space = height;
for (lineno = 1; lineno <= height; lineno++ )
{
for (space; space > 0; space--)
{
printf(".");
}
for (column_fill = 1; column_fill <= lineno; column_fill++)
{
printf("#");
}
printf("\n");
}
}
int get_height(void)
{
int height;
do
{
height = get_int("Height: ");
}while(height < 0 || height > 9);
return height;
}
我收到的錯誤是: mario.c:13:14: error: expression result used [-Werror,-Wunused-value] for (space; space > 0; space--) ^~~~~ 1 error生成. :目標“馬里奧”的配方失敗制作:*** [馬里奧] 錯誤 1
在for (space; space > 0; space--)
,第一個space
不做任何事情,編譯器會就此警告您。
通常, for
語句中的第一項要么是執行某些操作的表達式,例如賦值space = height
,要么是要在循環中使用的一個或多個對象的聲明,例如int space = height
。 將您的代碼更改為其中之一,編譯器將停止抱怨。
您可能應該使用后者並刪除先前單獨的space
聲明,因為:
space
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.