主题:求助
[[size=4][大家好!我是个编程新手,最近写了一个很简单的程序,调试程序的时候出现了下面的错误:
[b]135.exe 中的 0x102e14cf (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x00000061 时发生访问冲突[/b]
哪位好心人能告诉我是什么原因,是程序本身的原因吗?[/size][/size][/size][/size]
我是用VS2010写的程序:
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
void main()
{
int letter=0,digit=0,capital=0,small=0,space=0,others=0;
FILE *fp,*fp1;
char c;
errno_t err;
err=fopen_s(&fp,"1.txt","r");
if(err)
{
printf("the file1 was not opended\n");
exit(1);
}
else{
printf("the file1 was opened");
c=fgetc(fp);
while(c!='\n')
{
if(c>='A'&&c<='Z')
{
letter++;
capital++;
}
else if(c>='a'&&c<='z')
{
letter++;
small++;
}
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else others++;
printf("line is %s\n",c);
printf("letter is %2d\n",letter);
c=fgetc(fp);
}
}
err=fopen_s(&fp1,"2.txt","w+");
if(err)
{
printf("the file was not opened\n");
exit(1);
}
else
{
printf("the file2 was opened\n");
fprintf_s(fp1,"letter is %2d\n",letter);
fprintf_s(fp1,"capital is %2d\n",capital);
fprintf_s(fp1,"small is %2d\n",small);
fprintf_s(fp1,"space is %2d\n",space);
fprintf_s(fp1,"others is %2d\n",others);
}
fclose(fp);
fclose(fp1);
getchar();
}
[b]135.exe 中的 0x102e14cf (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x00000061 时发生访问冲突[/b]
哪位好心人能告诉我是什么原因,是程序本身的原因吗?[/size][/size][/size][/size]
我是用VS2010写的程序:
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
void main()
{
int letter=0,digit=0,capital=0,small=0,space=0,others=0;
FILE *fp,*fp1;
char c;
errno_t err;
err=fopen_s(&fp,"1.txt","r");
if(err)
{
printf("the file1 was not opended\n");
exit(1);
}
else{
printf("the file1 was opened");
c=fgetc(fp);
while(c!='\n')
{
if(c>='A'&&c<='Z')
{
letter++;
capital++;
}
else if(c>='a'&&c<='z')
{
letter++;
small++;
}
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else others++;
printf("line is %s\n",c);
printf("letter is %2d\n",letter);
c=fgetc(fp);
}
}
err=fopen_s(&fp1,"2.txt","w+");
if(err)
{
printf("the file was not opened\n");
exit(1);
}
else
{
printf("the file2 was opened\n");
fprintf_s(fp1,"letter is %2d\n",letter);
fprintf_s(fp1,"capital is %2d\n",capital);
fprintf_s(fp1,"small is %2d\n",small);
fprintf_s(fp1,"space is %2d\n",space);
fprintf_s(fp1,"others is %2d\n",others);
}
fclose(fp);
fclose(fp1);
getchar();
}