c语言 程序执行时 程序错误,!C程序运行时fprintf的异常。

当前位置:我的异常网» 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))

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值