关于“First-chance exception”

©2005 黄友生。本文由原作者发布于MSN Space、CSDN、www.veryinfo.com。你可以保存、在非商业软件中使用、在非盈利性文章中引用本文中的部分或全部文字,但请注明作者及原文地址。要用于其它用途,请先联系作者(eien@eyou.com)。作者不保证本文完全正确无误、不对因本文中的理论或代码缺陷造成的损失负责。

在VC中调试程序时,Output窗口有时会出现“First-chance exception in xxx.exe...”这样的信息。一般来说,这是由于程序中发生了异常,被VC捕获而产生的输出。

在调试器中运行程序时,如果程序产生异常,调试器会首先获得通知(即First-chance exception),而后此异常由产生它的程序负责捕获。如果程序没有捕获此异常,那么调试器会再次被通知(即Second-chance exception,Last-chance exception),并结束程序。

通常见到的“First-chance exception”一般是“0xC0000005: Access Violation”,“0xC00000FD: Stack Overflow”等,这些都说明程序中有缺陷,需要修正。

但是也有一些属于正常的情况,例如“First-chance exception in xxx.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception”。Windows 操作系统中广泛使用了结构化异常(SEH)来处理特殊情况,许多和底层打交道的API都靠SEH来处理可能发生的意外。并且,这些API中都有捕获SEH的代码,产生的异常不会对程序造成影响。但是由于上面提到的“First-chance exception,Second-chance exception”机制,VC仍然会有输出,但是我们完全可以忽略。如果你实在不喜欢这些输出信息,那你就必须禁用对特定异常的“First-chance exception”捕获。

展开阅读全文

First-chance exception at 0x7c812afb in *.exe

03-27

不知道各位高手是否遇到以下情况?rn环境:windows XP professional 32 位系统,cuda 4.1, VC 2008 MFC工程rn执行如下代码,情况如见注释:rn[code=C/C++]rn // 分配内存空间rn int nMemorySize = sizeof(Complex) * nSizeX * nSizeY; // 传入的参数是512*512,但是跟踪发现是很大的数字或者0rn Complex* pDeviceData;rn Complex* pDeviceDataCopy;rn cutilSafeCall(cudaMalloc((void**)&pDeviceData, nMemorySize)); // 该行被跳过执行rn cutilSafeCall(cudaMalloc((void**)&pDeviceDataCopy, nMemorySize)); // ##rn cutilSafeCall(cudaMemcpy(pDeviceData, pData, nMemorySize, cudaMemcpyHostToDevice));rn cutilSafeCall(cudaMemcpy(pDeviceDataCopy, pDeviceData, nMemorySize, cudaMemcpyDeviceToDevice));rnrn /* 对原始数据执行 FFT 变换 */rn cufftHandle plan;rn cufftSafeCall(cufftPlan2d(&plan, nSizeX, nSizeY, CUFFT_C2C));rn cufftSafeCall(cufftSetCompatibilityMode(plan, CUFFT_COMPATIBILITY_NATIVE));rn cufftSafeCall(cufftExecC2C(plan, (cufftComplex*)pDeviceData, (cufftComplex*)pDeviceData, CUFFT_FORWARD));rnrn /* 滤波 */rn float* pDeviceHanning;rn cutilSafeCall(cudaMalloc((void**)&pDeviceHanning, sizeof(float)*nSizeX*nSizeY));rn cutilSafeCall(cudaMemcpy(pDeviceHanning, pHanning, nMemorySize, cudaMemcpyHostToDevice)); // 执行该行后又回到 ## 处,此前 Output 一切正常,回到 ## 处后输出异常。rn LPFilter<<>>(pDeviceData, pDeviceHanning, nSizeX, nSizeY);rn[/code]rnrn输出的异常为:First-chance exception at 0x7c812afb in CerebralVeinExtract.exe: Microsoft C++ exception: cudaError_enum at memory location 0x0013ed0c..rn之后程序就进入 Exit 之类的函数,退出了,退出代码为-1。 论坛

First-chance exception in sitecheck.exe (KERNEL32.DLL)?

08-23

[code=C/C++]MainThread *ptr=(MainThread *)pParam;rn CString URL;rn if(!(ptr->mm_DownLoadData.GetCurURL(URL)))rn rn ptr->mm_DownLoadData.DeleThread();rn return 0;rn rn //以下为建立网络发出请求rn CInternetSession MyConnect("Microsoft MFC APP",1,INTERNET_OPEN_TYPE_DIRECT);rn CHttpConnection* pServer = NULL;rn CHttpFile* pHttpFile=NULL;rn rn // check to see if this is a reasonable URLrn CString strServerName;rn CString strObject;rn INTERNET_PORT nPort;rn DWORD dwServiceType;rn tryrn rn if (!AfxParseURL(URL, dwServiceType, strServerName, strObject, nPort) ||rn dwServiceType != INTERNET_SERVICE_HTTP)rn rn THROW(new CInternetException(dwServiceType));rn rn pServer=MyConnect.GetHttpConnection(strServerName, nPort);rn pHttpFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,rn strObject, NULL, 1, NULL, NULL);rn pHttpFile->AddRequestHeaders(_T("Accept: text/*\r\nUser-Agent: MFC\r\n"));rn pHttpFile->SendRequest();rn rn DWORD StatusCode;rn pHttpFile->QueryInfoStatusCode(StatusCode);rn rn //file isn't there or is redirectedrn if (StatusCode == HTTP_STATUS_MOVED ||StatusCode == HTTP_STATUS_REDIRECT ||rn StatusCode == HTTP_STATUS_REDIRECT_METHOD)rn rn CString strNewLocation;rn pHttpFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);rn rn int nPlace = strNewLocation.Find(_T("Location: "));rn if (nPlace == -1)rn rn THROW(new CInternetException(StatusCode));rn rn strNewLocation = strNewLocation.Mid(nPlace + 10);rn nPlace = strNewLocation.Find('\n');rn if (nPlace > 0)rn strNewLocation = strNewLocation.Left(nPlace);rn rn // close up the redirected sitern pHttpFile->Close();rn delete pHttpFile;rn pServer->Close();rn delete pServer;rn rn // figure out what the old place wasrn if (!AfxParseURL(strNewLocation, dwServiceType, strServerName, strObject, nPort))rn rn THROW(new CInternetException(StatusCode));rn rn rn if (dwServiceType != INTERNET_SERVICE_HTTP)rn rn THROW(new CInternetException(StatusCode));rn rn rn // try again at the new locationrn pServer = MyConnect.GetHttpConnection(strServerName, nPort);rn pHttpFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,rn strObject, NULL, 1, NULL, NULL);rn pHttpFile->AddRequestHeaders(_T("Accept: text/*\r\nUser-Agent: MFC\r\n"));rn pHttpFile->SendRequest();rn rn pHttpFile->QueryInfoStatusCode(StatusCode);rn rn rn if (StatusCode != HTTP_STATUS_OK)rn rn THROW(new CInternetException(StatusCode));rn rn rn rn catch(CInternetException *pEx)rn //出错处理rn if(pServer!=NULL)rn rn pServer->Close();rn delete pServer;rn rn if(pHttpFile!=NULL)rn rn pHttpFile->Close();rn delete pHttpFile;rn rn pEx->Delete();rn MyConnect.Close();rn ptr->mm_DownLoadData.DeleThread();rn ptr->AddString(URL+"\r\nDownload failed!\r\n",0);rn return 0;rn rn //message for "Connected"rn //if m_DownData is not full save the filern bool b=!(ptr->mm_DownLoadData.IsFull());rn CString str_FileName;rn ptr->mm_DownLoadData.GetFileName(str_FileName);rn //内容提取后保存为本地文件rn CStdioFile LocalFile;rn //本地临时文件rn CStdioFile tempLocalFile;rn LocalFile.Open(str_FileName,rn CFile::modeCreate|CFile::modeWrite|CFile::typeText);rn if(b)tempLocalFile.Open(str_FileName+".tmp",rn CFile::modeCreate|CFile::modeWrite|CFile::typeText);rn if(b)tempLocalFile.WriteString(URL+_T("\n"));rn LocalFile.WriteString(URL+_T("\n"));rn CString s;rn UINT w=0,k=0;rn int i=0,j=0;rn LPTSTR p;rn //找出本页的标题rn while(pHttpFile->ReadString(s))rn //每次读取一行rn if(b)tempLocalFile.WriteString(s+_T("\n"));rn i=s.Find(_T(" "));rn if(i==-1) i=s.Find(_T(" "));rn if(i==-1) i=s.Find(_T(" "));rn if(i!=-1)rn rn i+=7;rn j=s.Find(_T("</"),i);rn if(j!=-1)LocalFile.WriteString(s.Mid(i,j-i)+_T("\n"));rn elsern rn LocalFile.WriteString(s.Mid(i));rn while(pHttpFile->ReadString(s))rn rn if(b)tempLocalFile.WriteString(s+_T("\n"));rn j=s.Find(_T("</"));rn if(j==-1)rn rn LocalFile.WriteString(s);rn continue;rn rn LocalFile.WriteString(s.Left(j)+"\n");rn break;rn rn rn break;rn rn if(s.Find(_T("</HAED>"))!=-1 || s.Find(_T("</Head>"))!=-1 || s.Find(_T("</head>"))!=-1)rn rn LocalFile.WriteString(_T("Untitled Page\n"));rn break;rn rn ;rn bool body=false;rn while(pHttpFile->ReadString(s))rn rn if(b)tempLocalFile.WriteString(s+_T("\n"));rn if(s.Find(_T("')!=-1)break;rn rn //对主体内容的过滤rn while(pHttpFile->ReadString(s))rn rn if(b)tempLocalFile.WriteString(s+_T("\n"));rn rn p=s.GetBuffer(1024);rn /* ptr->TrimString(p,w,k,ptr->m_chinese);*/rn s.ReleaseBuffer();rn if(s!="")rn rn int f=0,g=0;rn //去除 符号rn while((g=s.Find(_T(" "),f))!=-1)rn rn s.Delete(g,6);rn s.Insert(g," ");rn f=g;rn rn s.TrimLeft();rn s.TrimRight();rn if(s!="")rn rn LocalFile.WriteString(s+_T(" "));rn rn rn rn LocalFile.Close();rn if(b)tempLocalFile.Close();rn //查找临时文件中的链接rn if(b)rn rn FindURL(str_FileName+_T(".tmp"),ptr);rn //删除临时文件rn DeleteFile(str_FileName+_T(".tmp"));rn rn rn rn pHttpFile->Close();rn delete pHttpFile;rn pServer->Close();rn delete pServer;rn MyConnect.Close();rn //状态显示rn ptr->AddString(URL+"\r\nDownload successfully!\r\n",1);rn/* ::PostMessage((HWND)pParam,WM_MYEDITRESTATUS,0,0);*/rn ptr->mm_DownLoadData.DeleThread();rn return 1;[/code]rnrn谁能帮我看看什么问题!能运行一段时间,过了一段时间,就会弹出上面标题的错误!我怀疑是catch 有问题 论坛

First-chance exception :0xC0000008:Invalid Handle

01-06

有一个支持多Client.Socekt连接的 Server.Socket程序,每当有一个Client.Socket请求连接的时候,Server.Socket程序中会通过new出来一块区域存放Custom.Socket来建立和Client.Socket连接,new出来的Custom.Socket又存放到一个CList 里面。在Socket Server关闭的时候,要将CList中存放的Custom.Socket一个一个的取出来,调用Custom.Socket.closesocket(),然后,再将CList清空。程序运行没什么问题,调试环境下,调用Clist.RemoveHead()(我是从头开始移除的)时候出现:rnFirst-chance exception in TCPServer.exe (NTDLL.DLL):0xC0000008:Invalid Handle。rn进入到Clist.RemoveHead()内部,发现,RemoveHead()语句都可以执行,最后return 的时候出现上述错误,并且returnvalue的值也是正确的。代码如下:rnCList m_ListClientSocket;rn有连接请求:rnif (FD_ISSET(pSocket->m_ServerSocket,&fdRead))rn rn //如果调用了Listen,则表示触发了OnAccept事件rn SOCKADDR_IN clientAddr;rn CTCPCustom_CE * pClientSocket = new CTCPCustom_CE(); rn int namelen = sizeof(clientAddr);rn //等待,创建与客户端连接的套接字rn pClientSocket->m_socket = accept(pSocket->m_ServerSocket, (struct sockaddr *)&clientAddr, &namelen);rn //接收到客户端连接rn if (pClientSocket->m_socket)rn rn pClientSocket->m_RemoteHost = inet_ntoa(clientAddr.sin_addr);rn pClientSocket->m_RemotePort = ntohs(clientAddr.sin_port);rn rn //触发与客户端建立连接事件rn pSocket->OnClientConnect(pSocket->m_pOwnerWnd,pClientSocket);rn //打开pClientSocket服务线程rn pClientSocket->Open(pSocket);rn //添加到客户端连接队列中rn m_ListClientSocket.AddTail(*pClientSocket); rn /*pClientSocketTemp=pClientSocket;*/rn rn elsern rn delete pClientSocket; rn rn rnServer.Socket关闭的部分:rnPOSITION pos = m_ListClientSocket.GetHeadPosition();rn while (pos != NULL)rn rn CTCPCustom_CE &tmpTcpCustom = m_ListClientSocket.GetAt(pos);rn if (!tmpTcpCustom.Close())rn rn AfxMessageBox("关闭客户端socket错误");rn rn m_ListClientSocket.RemoveHead();////这里调试的时候会出错,如前所述。rn pos = m_ListClientSocket.GetHeadPosition();rn rn问题:请大侠们分析出现在RemoveHead出现 First-chance exception in TCPServer.exe (NTDLL.DLL):0xC0000008:Invalid Handle rn另外请问,那些new出来的,放在Clist中的Custom.Socket所占的内存会不会在RemoveHead的时候被一起释放掉? 论坛

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

05-06

#includern#include "c.h"rnusing namespace std;rnrn#define STACK_INIT_SIZE 100rn#define STACKINCREMENT 10rnrntemplateclass SqStackrnrn public:rn T *base;rn T *top;rn T e;rn int size;rn public:rn void InitStack(SqStack)//声明栈建立函数rn rn base=(T *)malloc(STACK_INIT_SIZE *sizeof(T));rn if(!base)cout<<"存储分配失败!";//存储分配失败rn top=base;rn size=STACK_INIT_SIZE;rn rn void Push(T e)//入栈rn rn if((top - base)>=size)//栈满,追加存储空间rn rn base=(T *)realloc(base,(size+STACKINCREMENT)*sizeof(T));rn if(!base)cout<<"存储分配失败!";rn elsern rn top=base+size;rn size=size+STACKINCREMENT;rn rn rn *top=e;rn top = top+1;//将元素e入栈,指针上移rn rn T GetTop()//取栈顶元素rn rn T e;rn if(top==base)cout<<"\n运算符栈已空!\n";rn else e=*(top-1);rn return e;rn rn T Pop()//出栈rn rn T e;rn if(top==base)cout<<"\n运算符栈已空!\n";rn e=*(--top);rn return e;rn rn /* void DispStack()//从栈底到栈顶依次输出各元素rn rn T e,*p;rn if(top==base)cout<<" ";rn elsern rn p=base;rn while(pclass Evaluaternrn private:rn char c,m,n;rn float a,b;rn bool Operator(char c); //判断c是否为7中运算符之一rn float Operate(float a,char c,float b); //运算函数rn char Compare(char m,char n); //运算符的优先级比较rn public:rn void Expression();rn;rnrnbool Evaluate::Operator(char c) //判断c是否为7中运算符之一rnrn switch (c)rn rn case '+':rn case '-':rn case '*':rn case '/':rn case '(':rn case ')':rn case '#': return true;rn default: return false;rn rnrnrnfloat Evaluate::Operate(float a,char c,float b) //运算函数rnrn float sum=0;rn if (c=='+') sum=a+b; //从运算符栈取出的符号为"+",则运算数栈的两元素相加,并返回rn else if(c=='-') sum=a-b; //从运算符栈取出的符号为"-",则运算数栈的两元素相减,并返回rn else if(c=='*') sum=a*b; //从运算符栈取出的符号为"*",则运算数栈的两元素相乘,并返回rn else if(c=='/') //从运算符栈取出的符号为"/",则运算数栈的两元素相除,并返回rn rn if(b==0) cout<<"\n表达式出错!除数不能为0!\n";rn else sum=a/b;rn rn return sum;rnrnrnchar Evaluate::Compare(char m,char n) //运算符的优先级比较rnrn if(n=='+'||n=='-') //输入符号为"+"、"-"rn rn if(m=='('||m=='#')return '<'; //栈顶元素为"("、"#",此时栈顶符号优先级低,返回"<"rn else return '>'; //否则,栈顶符号优先级高,返回">"rn rn else if(n=='*'||n=='/') //输入的符号为"*"、"/"rn rn if(m==')'||m=='*'||m=='/')return '>'; //栈顶元素为")"、"*"、"/",此时栈顶符号优先级高,返回">"rn else return '<'; //否则,栈顶符号优先级低,返回"<"rn rn else if(n=='(')return'<'; //输入的符号为"(",则直接返回"<"rn else if(n==')') //输入的符号为")"rn rn if(m=='(')return'='; //栈顶元素为"(",此时优先级同,返回"="rn else return '>'; //否则,栈顶符号优先级高,返回">"rn rn else //输入符号为其他rn rn if(m=='#')return'='; //栈顶元素为"#",此时优先级同,返回"="rn else return '>'; //否则,栈顶符号优先级高,返回">"rn rnrnrnvoid Evaluate::Expression()rnrn SqStack OPTR;rn SqStack OPND;rnrn char c;rn float t,e,p1,p2;rn int n=0,i=1,j=0,l=0;rn char w[STACK_INIT_SIZE];rnrn cout<<"请输入算术表达式,负数用(0-正数)表示,以'#'结束:\n "<>w;rn c=w[0];rn// w=w +'#';rn int s=1;rn char ch1;rn OPTR.Push('#');//将'#'入栈,作为低级运算符rn c=w[0];rn while(c!='#'||OPTR.GetTop()!='#')rn rnqq:rn if(!Operator(c))//输入的字符如果不是运算符号,则继续输入直到输入的是运算符为止,将非运算符转换成浮点数rn rn if(!(c=='.')&&n>=0)rn rn e=float(c-48);rn n++;rn if(n==1)t=e;rn else if(n>1)t=t*10+e;rn c=w[s++];rn rn if(n==-1)rn rn e=float(c-48);rn t=t+e/10;rn c=w[s++];rn rn if(c=='.')rn rn n=-1;rn c=w[s++];rn rn if((c>='0'&&c<='9')||c=='.')rn rn goto qq;rn rn if(c<'0'||c>'9') rn rn OPND.Push(t);rn rn rn else//输入的是运算符rn rn n=0;//非运算型数据计数器清零rn switch(Compare(OPTR.GetTop(),c))//比较运算符优先级rn rn case '<'://栈顶元素优先级低,则入栈且继续输入rn OPTR.Push(c);rn c=w[s++];rn break;rn case '='://栈顶元素优先级相等,脱括号并接收下一字符rn OPTR.Pop();rn c=w[s++];rn break;rn case '>'://栈顶元素优先级高,则退栈并将运算结果入栈 rn p1=OPND.Pop();rn p2=OPND.Pop();rn ch1=OPTR.Pop();rn OPND.Push(Operate(p2,ch1,p1));rn break;rn rn rn rn if(OPND.top-1==OPND.base)//显示表达式的最终结果rn cout<<"\n表达式的结果为:"< E;rn E.Expression();rn// cout<<"请输入算术表达式,负数用(0-正数)表示:"<>w;rn// cout<<"表达式结果等于" E.Expression(w);rnrnrnrnrn此程序在运行时出现“First-chance exception in biaodashiqiuzhi.exe: 0xC0000005: Access Violation.”rn请问是什么问题?该如何解决? 论坛

First-chance exception in (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exceptio

11-11

一个MFC程序,调用存储过程,在执行到cmd->Execute( NULL ,NULL, adCmdStoredProc );rn的时候就报出 rn exception in (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception 错误!rnvoid CBALANCE::OnQueryBalance() rnrn // TODO: Add your control notification handler code herern UpdateData( TRUE );rn if ( m_phoneno == "" )rn rn MessageBox( "请输入要查询的电话号码!", "余额查询", MB_OK );rn return;rn rn _CommandPtr cmd; // 命令对象rn _ParameterPtr param; // 参数对象rn char stresult[1024]; // 返回值rn HRESULT hr = cmd.CreateInstance( __uuidof( Command ) );rn if ( FAILED( hr ) )rn rn MessageBox( "调用存储过程时CreateInstance出现错误!", "提示", MB_OK );rn return;rn rn /*填写参数*/rn param = cmd->CreateParameter( "VPHONE", adVarChar, adParamInput, m_phoneno.GetLength() + 1, _variant_t( m_phoneno ) );//电话号码rn cmd->Parameters->Append( param );rn param = cmd->CreateParameter( "VRESULT", adVarChar, adParamOutput, 1024, _variant_t( stresult ) );rn cmd->Parameters->Append( param );rn /*执行存储过程*/rn cmd->ActiveConnection = database.pDBConn;rn cmd->CommandType = adCmdStoredProc;rn cmd->CommandText = _bstr_t("PKG_CHECK.GETCHARGE");rn cmd->Execute( NULL ,NULL, adCmdStoredProc );rn /*获取返回值*/rn strcpy(stresult,(char*)_bstr_t(cmd->Parameters->GetItem("VRESULT")->GetValue()));rn m_list.SetWindowText( "" );rn UpdateData( FALSE );rn //m_list.DeleteAllItems();rn //m_list.SetWindowText( stresult );rn m_list.SetWindowText( stresult );rn cmd.Detach();rnrn是怎么回事?rn 论坛

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

10-13

看了一些类似的帖子可是我的问题还是无法解决。请各位高手赐教,谢谢。rnrn错误信息是:rnLoaded 'ntdll.dll', no matching symbolic information found.rnLoaded 'H:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.rnFirst-chance exception in TONGJI.exe: 0xC0000005: Access Violation.rnrnrnrn代码是:rnrn#include rn#include rn#include rn#include rn#include rnrn#include "stack.h"rn#define _ss ".\\tc.txt"//文件路径rnrnrnvoid main()rnrn FILE *fp;FILE *OUT;rn cSqStack S,S1;rn char ch;int n=0,i,counter=0,letterCounter=0;/*计数器*/rn int count=0;/*新加计数器*/rn int countct=0,wordct=0;rn char string[20];rn char tmp;rn char str[5120][20];int strnum[5120];/*记录单词,单词种类数*/rn int letter[26]=0;rn float ltmp=0.0;/*求字母的频率*/rn clock_t start,end;rn start=clock();rn fp=fopen(_ss,"r");rn if (fp==NULL)rn rn printf("File(tc.txt) opened failed!!!\n");rn getch();rn exit(1);rn rn OUT=fopen(".\\结果.txt","w");rn if (OUT==NULL)rn rn printf("File(tc.txt) creat failed!!!\n");rn getch();rn exit(1);rn rn while((ch=fgetc(fp))!=EOF)rn rn if(ch>='a'&&ch<='z')letter[ch-'a']++;letterCounter++;rn if(ch>='A'&&ch<='Z')letter[ch-'A']++;letterCounter++;rn rn /*不区分大小写的统计字符频率*/rn fclose(fp);rnrnrnrn printf("\n程序正在运行...");rn fprintf(OUT,"\n\n******************************************统计文章War and peace的字符信息*************************************************\n\n");rn for (i=0;i<26;i++)rn rn tmp=i+'a';rn ltmp=(float)letter[i]/letterCounter*100;/*求各字母的频率,不区分大小写*/rn fprintf(OUT,"%-c:%-6d %%%-4.2f ",tmp,letter[i],ltmp);counter++;rn if(counter%5==0)fprintf(OUT,"\n--------------------------------------------------------------------------------------------------------------------\n");rn rn fprintf(OUT,"字符个数:%d",letterCounter);rnrn InitStack(&S);/*工作栈的初始化*/rn InitStack(&S1);rn fp=fopen(_ss,"r");rn if (fp==NULL)rn rn printf("File opened failed!!!\n");rn getch();rn exit(1);rn rn while((ch=fgetc(fp))!=EOF)rn rn if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')rn cPush(&S,ch);rn elsern rn cPush(&S,'\0');rn if(!StackEmpty(&S))rn i=0;rn while(!StackEmpty(&S))rn rn cPush(&S1,cPop(&S));rn rn wordct++;/*记录单词数量*/rn while(!StackEmpty(&S1))rn rn string[i++]=cPop(&S1);rn rn n=0;rn while (n=count) strcpy(str[count],string);strnum[count]=1;count++;/*比对string没发现,向str[][]中添加新的字符串*/rn rn rn /*可以从文件流中剥离一个个的单词了*/rnrn fprintf(OUT,"单词个数:%d",wordct);rn fprintf(OUT,"\n双频词\n");rn for (i=0;ibase=(char *)malloc(STACK_INIT_SIZE*sizeof(char));rn if(!S->base)exit(OVERFLOW);rn S->top=S->base;rn S->stacksize=STACK_INIT_SIZE;rn return OK;rnrnchar cGetTop(cSqStack *S)rnrn char e;rn if(S->top==S->base)return ERROR;rn e=*(S->top-1);rn return e;rnrnrnint cPush(cSqStack *S,char e)rnrn if(S->top-S->base>=S->stacksize)rn rn S->base=(char *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(char));rn if(!S->base)exit(OVERFLOW);rn S->top=S->base+S->stacksize;rn S->stacksize+=STACKINCREMENT;rn rn *S->top++=e;rn return OK;rnrn/*插入e为新的栈顶元素*/rnrnchar cPop(cSqStack *S)rnrn char e;rn if(S->top==S->base)return ERROR;/*error 0*/rn e=*--S->top;rn return e;rn/*若栈不为空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR*/rnrnrnint StackEmpty(cSqStack *S)rnrn if(S->top==S->base)return 1;/*1栈空*/rn else return 0;rn/*判断栈是否为空*/rnrnint cStackLength(cSqStack *S)rnrn char *p;rn int i=0;rn p=S->top;rn while(p!=S->base) i++;p=p-1;rn return i-1;rn/*返回栈的长度,即S的元素个数*/rnrn 论坛

没有更多推荐了,返回首页