我有Windows 8與vs2010,當我運行這部分程序時顯示此錯誤: 運行時檢查失敗#2 - 圍繞變量「seqA」已損壞。 ................................................. .............................運行時檢查失敗#2 - 圍繞變量'seqA'的堆棧損壞
#include <iostream.h>
#include <stdio.h>
#include <string>
#include<stdlib.h>
#include <fstream>
using namespace std;
int main(){
int lenA = 0;
int lenB = 0;
FILE * fileA, * fileB;
char holder;
char seqA[10], seqB[10];
/*open first file*/
fileA=fopen("c:\\str1.fa", "r");
/*check to see if it opened okay*/
if(fileA == NULL) {
perror ("Error opening 'str1.fa'\n");
exit(EXIT_FAILURE);
}
/*open second file*/
fileB = fopen("c:\\str2.fa", "r");
/*check to see if it opened okay*/
if(fileB == NULL) {
perror ("Error opening 'str1.fa'\n");
exit(EXIT_FAILURE);
}
/*measure file1 length*/
while(fgetc(fileA) != EOF) {
holder = fgetc(fileA);
seqA[lenA]=holder;
lenA++;
}
lenA--;
fclose(fileA);
holder='0';
/*measure file2 length*/
while(fgetc(fileB) != EOF) {
holder = fgetc(fileB);
seqB[lenB]=holder;
lenB++;
}
lenB--;
fclose(fileB);
鏈接picture此錯誤。
除非您的文件少於10個字節,否則您正在寫入已分配數組的末尾。 – 2013-03-01 20:07:24