txt12.exe 中的 0x0f96c9c7 (msvcr100d.dll) 处有未经处理的错误: 0xC0000005: 写入位置 0x00140000 时
txt12.exe 中的 0x0f96c9c7 (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 写入位置 0x00140000 时
#include <iostream>
using namespace std;
#define FRISTCLM 30000
#define SECONDCLM 8
//参数ais.txt 为要读的文件名,如:readdd.txt 。
int ReadFileToBUF(char * ais,int bufdd[][SECONDCLM],int len)
{
FILE *fp=fopen("ais.txt","r");
if(fp == NULL)
return 0;
char buf[256],numberbuf[10];
char * cur,* p;
int index,index1;
int temp[SECONDCLM];
int allcount=0;
while(!feof(fp))
{
memset(buf, 0, 256);
fgets(buf, 256, fp);
//去掉最后一个字符,可能是换行符
index=strlen(buf);
if(index>0)
{
if(buf[index-1]=='\n' || buf[index-1]=='\r')
buf[index-1]=0x00;
}
else
continue;
cur=buf;
if(!cur)
break;
while(*cur==' ')//去右边空格
cur++;
p=cur;
cur=strstr(cur,",");
index=cur-p;
memset(numberbuf,0,10);
memcpy(numberbuf,p,index);
temp[0]=atoi(numberbuf);
index1=1;
cur++;
while(*cur)
{//开始分析
// ctrlCombox.AddString(strcom);
p=cur;
cur=strstr(cur,",");
if(!cur)
{
if(index1 <SECONDCLM)
temp[index1]=atoi(p);
index1++;
printf("buf[0][0]");
break;
}
index=cur-p;
memset(numberbuf,0,10);
memcpy(numberbuf,p,index);
if(index1 <8)
temp[index1]=atoi(numberbuf);
cur++;
index1++;
}
if(index1==SECONDCLM)//读出来有误的不保存,缺少,或多了的也不保存
{
if(len>allcount)
{
for(int i=0;i<SECONDCLM;i++)
bufdd[allcount][i]=temp[i];
printf("buf[0][0]");
}
allcount++;
}
}
fclose(fp);
return allcount;
}
void showallbuf(int buf[][SECONDCLM],int len)
{
for(int k=0;k<len;k++)
{
for(int i=0;i<8;i++)
{
std::cout<<buf[k][i]<<" ";
printf("buf[0][0]");
}
}
std::cout<<std::endl;
}
int main()
{
int buf[FRISTCLM][SECONDCLM]={0};
int count=ReadFileToBUF("ais.txt",buf,FRISTCLM);
showallbuf(buf,count);
return 0;
printf("buf[0][0]");
}
------解决方案--------------------
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。
#include <iostream>
using namespace std;
#define FRISTCLM 30000
#define SECONDCLM 8
//参数ais.txt 为要读的文件名,如:readdd.txt 。
int ReadFileToBUF(char * ais,int bufdd[][SECONDCLM],int len)
{
FILE *fp=fopen("ais.txt","r");
if(fp == NULL)
return 0;
char buf[256],numberbuf[10];
char * cur,* p;
int index,index1;
int temp[SECONDCLM];
int allcount=0;
while(!feof(fp))
{
memset(buf, 0, 256);
fgets(buf, 256, fp);
//去掉最后一个字符,可能是换行符
index=strlen(buf);
if(index>0)
{
if(buf[index-1]=='\n' || buf[index-1]=='\r')
buf[index-1]=0x00;
}
else
continue;
cur=buf;
if(!cur)
break;
while(*cur==' ')//去右边空格
cur++;
p=cur;
cur=strstr(cur,",");
index=cur-p;
memset(numberbuf,0,10);
memcpy(numberbuf,p,index);
temp[0]=atoi(numberbuf);
index1=1;
cur++;
while(*cur)
{//开始分析
// ctrlCombox.AddString(strcom);
p=cur;
cur=strstr(cur,",");
if(!cur)
{
if(index1 <SECONDCLM)
temp[index1]=atoi(p);
index1++;
printf("buf[0][0]");
break;
}
index=cur-p;
memset(numberbuf,0,10);
memcpy(numberbuf,p,index);
if(index1 <8)
temp[index1]=atoi(numberbuf);
cur++;
index1++;
}
if(index1==SECONDCLM)//读出来有误的不保存,缺少,或多了的也不保存
{
if(len>allcount)
{
for(int i=0;i<SECONDCLM;i++)
bufdd[allcount][i]=temp[i];
printf("buf[0][0]");
}
allcount++;
}
}
fclose(fp);
return allcount;
}
void showallbuf(int buf[][SECONDCLM],int len)
{
for(int k=0;k<len;k++)
{
for(int i=0;i<8;i++)
{
std::cout<<buf[k][i]<<" ";
printf("buf[0][0]");
}
}
std::cout<<std::endl;
}
int main()
{
int buf[FRISTCLM][SECONDCLM]={0};
int count=ReadFileToBUF("ais.txt",buf,FRISTCLM);
showallbuf(buf,count);
return 0;
printf("buf[0][0]");
}
------解决方案--------------------
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。