執行時發生錯誤 (SIGSEGV)(11)!!
Segmentation fault, an address reference boundary error.(記憶體區段錯誤)
可能原因為:
* 通常為使用超過陣列範圍
* 指標指向不正確位址!
* 陣列初始化不正確!
* 嘗試在執行時期定義陣列長度!
sh: line 1: 17683 程式記憶體區段錯誤
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int i, j, sum;
char *_p[] = {"10", "11", "12", "13", "14", "15", "16", "17", "34", "18"
, "19", "20", "21", "22", "35", "23", "24", "25", "26", "27", "28"
, "29", "32", "30", "31", "33"};
char _id[10] = {'\0'};
while (cin >> _id) {
j = _id[0] - 'A';
sum = (*_p[j] - '0') + ((*(_p[j]+1)-'0')*9);
sum += (_id[9]-'0');
i = 0;
while(++i<9) {
j = (_id[i]-'0')*(9-i);
sum += j;
}
if ((sum%10)) {
cout << "fake";
} else {
cout << "real";
}
cout <<endl;
}
return 0;
}
執行時發生錯誤 (SIGSEGV)(11)!!
Segmentation fault, an address reference boundary error.(記憶體區段錯誤)
可能原因為:
* 通常為使用超過陣列範圍
* 指標指向不正確位址!
* 陣列初始化不正確!
* 嘗試在執行時期定義陣列長度!
sh: line 1: 17683 程式記憶體區段錯誤
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
int i, j, sum;
char *_p[] = {"10", "11", "12", "13", "14", "15", "16", "17", "34", "18"
, "19", "20", "21", "22", "35", "23", "24", "25", "26", "27", "28"
, "29", "32", "30", "31", "33"};
char _id[10] = {'\0'};
while (cin >> _id) {
j = _id[0] - 'A';
sum = (*_p[j] - '0') + ((*(_p[j]+1)-'0')*9);
sum += (_id[9]-'0');
i = 0;
while(++i<9) {
j = (_id[i]-'0')*(9-i);
sum += j;
}
if ((sum%10)) {
cout << "fake";
} else {
cout << "real";
}
cout <
}
return 0;
}
======
自問自答
用11