name lookup of 'i' change for ISO 'for' scoping[-fpermissive]
我的程序有什麼問題? -fpermissive
這是什麼意思?
我的代碼有什麼問題?
的代碼應該計算摩爾質量:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define maxn 1000
int main() {
double c = 12.01, h = 1.008, n = 14.01, o = 16.00, sum = 0, al, num;
char mol[maxn];
scanf("%s", mol);
for (int i = 0; i < strlen(mol); i++);
{
if (isalpha(mol[i])) {
if (mol[i] == 'C')
al = c;
if (mol[i] == 'H')
al = h;
if (mol[i] == 'O')
al = o;
if (mol[i] == 'N')
al = n;
if (isalpha(mol[i + 1]))
sum += al;
else {
num = mol[i + 1] - '0';
sum += al * num;
}
}
}
printf("%lf\n", sum);
return 0;
}
參見';'在'爲(...)'行的末尾?因爲這個原因,你有效地使用了未聲明的'i'作爲'for'循環體的'mol'索引。 –
可能的重複[錯誤消息:'jj'的名稱查找已針對'範圍確定'更改爲ISO(如果使用'-fpermissive',則G ++將接受您的代碼)](http://stackoverflow.com/questions/6556449/錯誤消息名稱查找的jj更改爲iso作爲範圍,如果你使用) –
在c中不允許在'for'語句中聲明變量。在'for'語句之前移動'int i;'。如果你想在你的循環中做任何事情,你還應該從'for'的行中刪除';'。 – woockashek