当前位置:我的异常网» C语言 » !C程序运行时fprintf的异常。
!C程序运行时fprintf的异常。
www.myexceptions.net 网友分享于:2013-12-27 浏览:38次
求助!!!C程序运行时fprintf的错误。。。
程序运行时出现下面的错误:
File:fprintf.c
Expression: str!=NULL
向各位大牛请教一下,不胜感激!!!
代码如下:
#include
#include
#include
#include
#include"scan.h"
/* lexeme of identifier or reserved word */
char tokenString[MAXTOKENLEN+1];
/* BUFLEN = length of the input buffer for
source code lines */
#define BUFLEN 256
static char lineBuf[BUFLEN]; /* holds the current line */
static int linepos = 0; /* current position in LineBuf */
static int bufsize = 0; /* current size of buffer string */
static bool EOF_flag = false; /* corrects ungetNextChar behavior on EOF */
FILE* source; /* source code text file */
FILE* listing; /* listing output text file */
FILE* code; /* code text file for TM simulator */
int lineno = 1; /* source line number for listing */
/* getNextChar fetches the next non-blank character
from lineBuf, reading in a new line if lineBuf is
exhausted */
static int getNextChar(void)
{
if (!(linepos < bufsize))
{ lineno++;
if (fgets(lineBuf,BUFLEN-1,source))
{ if (true) fprintf(listing,"%4d: %s",lineno,lineBuf);
bufsize = strlen(lineBuf);
linepos = 0;
return lineBuf[linepos++];
}
else
{ EOF_flag = true;
return EOF;
}
}
else
return lineBuf[linepos++];
}
/* ungetNextChar backtracks one character
in lineBuf */
static void ungetNextChar(void)
{
if (!EOF_flag)
linepos-- ;
}
/* lookup an identifier to see if it is a reserved word */
/* uses linear search */
static TokenType reservedLookup (char * s)
{
if (!strcmp(s,reservedWords.str))
return reservedWords.tok;
return ID;
}
void printToken(TokenType currentToken,char tokenString[])
{
fprintf(code,"\n",currentToken,tokenString);
}
/* function getToken returns the
* next token in source file
*/
TokenType getToken(void)
{ /* index for storing into tokenString */
int tokenStringIndex = 0;
/* holds current token to be returned */
TokenType currentToken;
/* current state - always begins at START */
StateType state = START;
/* flag to indicate save to tokenString */
bool save;
while (state != DONE)
{
int c = getNextChar();
save = true;
switch (state)
{
case START:
if (isalpha(c))
state = INID;
else if (c == '+')
state = TRANS1;
else if (c == '-')
state = TRANS2;
else if (isdigit(c))
state = INNUM1;
else if (c == ':')
state = INEQ;
else if ((c == ' ') || (c == '\t') || (c == '\n'))
save = false;
else
{
state = DONE;
switch (c)
{
case EOF:
save = false;
currentToken = ENDFILE;
break;
case ',':
currentToken = COMMA;
break;
case '(':
currentToken = LPAREN;
break;
case ')':
currentToken = RPAREN;
break;
case ';':
currentToken = SEMI;
break;
default:
currentToken = ERROR;
break;
}
}
break;
case INEQ:
state = DONE;
if (c == '=')
currentToken = EQ;
else
{ /* backup in the input */
ungetNextChar();
save = false;
currentToken = ERROR;
}
break;
case INID:
if (!isalpha(c) || !isdigit(c))
文章评论