First-chance exception in TONGJI.exe: 0xC0000005: Access Violation.

neo20 2007-10-13 10:38:59
看了一些类似的帖子可是我的问题还是无法解决。请各位高手赐教,谢谢。

错误信息是:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'H:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
First-chance exception in TONGJI.exe: 0xC0000005: Access Violation.



代码是:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include "stack.h"
#define _ss ".\\tc.txt"//文件路径


void main()
{
FILE *fp;FILE *OUT;
cSqStack S,S1;
char ch;int n=0,i,counter=0,letterCounter=0;/*计数器*/
int count=0;/*新加计数器*/
int countct=0,wordct=0;
char string[20];
char tmp;
char str[5120][20];int strnum[5120];/*记录单词,单词种类数*/
int letter[26]={0};
float ltmp=0.0;/*求字母的频率*/
clock_t start,end;
start=clock();
fp=fopen(_ss,"r");
if (fp==NULL)
{
printf("File(tc.txt) opened failed!!!\n");
getch();
exit(1);
}
OUT=fopen(".\\结果.txt","w");
if (OUT==NULL)
{
printf("File(tc.txt) creat failed!!!\n");
getch();
exit(1);
}
while((ch=fgetc(fp))!=EOF)
{
if(ch>='a'&&ch<='z'){letter[ch-'a']++;letterCounter++;}
if(ch>='A'&&ch<='Z'){letter[ch-'A']++;letterCounter++;}
}
/*不区分大小写的统计字符频率*/
fclose(fp);



printf("\n程序正在运行...");
fprintf(OUT,"\n\n******************************************统计文章War and peace的字符信息*************************************************\n\n");
for (i=0;i<26;i++)
{
tmp=i+'a';
ltmp=(float)letter[i]/letterCounter*100;/*求各字母的频率,不区分大小写*/
fprintf(OUT,"%-c:%-6d %%%-4.2f ",tmp,letter[i],ltmp);counter++;
if(counter%5==0)fprintf(OUT,"\n--------------------------------------------------------------------------------------------------------------------\n");
}
fprintf(OUT,"字符个数:%d",letterCounter);

InitStack(&S);/*工作栈的初始化*/
InitStack(&S1);
fp=fopen(_ss,"r");
if (fp==NULL)
{
printf("File opened failed!!!\n");
getch();
exit(1);
}
while((ch=fgetc(fp))!=EOF)
{
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
{cPush(&S,ch);}
else
{
cPush(&S,'\0');
if(!StackEmpty(&S))
{ i=0;
while(!StackEmpty(&S))
{
cPush(&S1,cPop(&S));
}
wordct++;/*记录单词数量*/
while(!StackEmpty(&S1))
{
string[i++]=cPop(&S1);
}
n=0;
while (n<count)/*n=0 count =0*/
{
if (strcmp(str[n],string)!=0)n++;
else {strnum[n]++;break;}/*在数组中找到与string相同的字符串,string[n]++*/
}
if(n>=count) {strcpy(str[count],string);strnum[count]=1;count++;}/*比对string没发现,向str[][]中添加新的字符串*/
}
}
}/*可以从文件流中剥离一个个的单词了*/

fprintf(OUT,"单词个数:%d",wordct);
fprintf(OUT,"\n双频词\n");
for (i=0;i<count;i++)
{
if(strlen(str[i])==2)
{fprintf(OUT,"%5s=%6d,%10f%% ",str[i],strnum[i],(float)strnum[i]/wordct*100);
countct++;
if(countct%5==0)fprintf(OUT,"\n");}
}

fprintf(OUT,"\n三频词\n");
countct=0;
for (i=0;i<count;i++)
{
if(strlen(str[i])==3)
{fprintf(OUT,"%5s=%6d,%10f%% ",str[i],strnum[i],(float)strnum[i]/wordct*100);countct++;
if(countct%5==0)fprintf(OUT,"\n");}
}/*打印提示信息*/
printf("\n运算结束.\n统计结果在: 结果.txt中\n");
end=clock();
fprintf(OUT,"\n总耗时:%f秒",(float)(end-start)/CLK_TCK);
fclose(fp);fclose(OUT);
getch();
}

/************头文件stack.h********************/

#define TURE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2

#define STACK_INIT_SIZE 10
#define STACKINCREMENT 10

typedef struct
{
char *base;
char *top;
int stacksize;
}cSqStack;/*字符型*/

int InitStack(cSqStack *S)
{
S->base=(char *)malloc(STACK_INIT_SIZE*sizeof(char));
if(!S->base)exit(OVERFLOW);
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
char cGetTop(cSqStack *S)
{
char e;
if(S->top==S->base)return ERROR;
e=*(S->top-1);
return e;
}

int cPush(cSqStack *S,char e)
{
if(S->top-S->base>=S->stacksize)
{
S->base=(char *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(char));
if(!S->base)exit(OVERFLOW);
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*S->top++=e;
return OK;
}
/*插入e为新的栈顶元素*/

char cPop(cSqStack *S)
{
char e;
if(S->top==S->base)return ERROR;/*error 0*/
e=*--S->top;
return e;
}/*若栈不为空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR*/


int StackEmpty(cSqStack *S)
{
if(S->top==S->base)return 1;/*1栈空*/
else return 0;
}/*判断栈是否为空*/

int cStackLength(cSqStack *S)
{
char *p;
int i=0;
p=S->top;
while(p!=S->base) { i++;p=p-1;}
return i-1;
}/*返回栈的长度,即S的元素个数*/

...全文
359 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧