| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 722 人关注过本帖
标题:急死了还有二天要交大作业了,一个结点赋值却总是要出错!
只看楼主 加入收藏
空明七心
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-3-18
收藏
 问题点数:0 回复次数:0 
急死了还有二天要交大作业了,一个结点赋值却总是要出错!
老师布置的大作业,一共有main.c, fileADT.c, fileADT.h三个文件组成),好不容易开通宵整出来了,编译也通过了,可是在"命令提示符"状态下一运行(book-unformatted和book-formatted是老师指定的):

main book-unformatted book-formatted

windows就提示main.exe遇到问题要关闭.
现在发现问题是在文件关闭时,要把头结点的值赋给行结点的值,就是下面这句出错:
linenodeptr = fileADT->line1;

二个结点的定义是这样的:
typedef struct fileADT
{
int size;
struct linenode * line1;
} FileADT;



typedef struct linenode
{
struct chnode * chhead;
struct linenode *nextline;
} LINENODE;

打开和关闭文件的函数如下:
int FileOpen(FileADT* fileADT, char* filename)
{
FILE *stream;
char readch;
LINENODE * linenodeptr;
CHNODE * chnodeptr = NULL;

stream = fopen( filename, "r" );
if( stream == NULL )
{
return -1;
}

fileADT = (FileADT*) malloc (sizeof(FileADT*));

//if (fileADT==NULL)
//{printf("Error!");
//return 0;
//}


linenodeptr =(LINENODE*) malloc( sizeof(LINENODE) );
if( linenodeptr != NULL )
{
linenodeptr->nextline = NULL;
linenodeptr->chhead = NULL;
fileADT->line1 = linenodeptr;
printf("%d", fileADT->line1);

}

while (fread( &readch, sizeof(char), 1, stream )>0 )
{
CHNODE * chnode;

chnode = (CHNODE *) malloc( sizeof(CHNODE) );

chnode->ch = readch;
chnode->nextch = NULL;

if( chnodeptr == NULL )
{
LINENODE * linenode;
linenode = (LINENODE *) malloc( sizeof(LINENODE) );

linenode->nextline = NULL;
linenode->chhead = chnode;
chnodeptr = chnode;

linenodeptr->nextline = linenode;
linenodeptr = linenode;
}
else
{
chnodeptr->nextch = chnode;
chnodeptr = chnode;
}
if( readch == '\n' )
{
chnodeptr = NULL;
}
}
fclose( stream );

return 0;

int FileClose(FileADT* fileADT, char* filename)
{
FILE *stream;
LINENODE* linenodeptr;
CHNODE * chnodeptr;

printf("%d", fileADT->line1);
linenodeptr = fileADT->line1;


stream = fopen( filename, "w" );
if( stream == NULL )
{
return -1;
}

while( linenodeptr != NULL )
{
chnodeptr = linenodeptr->chhead;
while( chnodeptr != NULL )
{
fwrite(&(chnodeptr->ch), sizeof(char), 1, stream );
chnodeptr = chnodeptr->nextch;
}
linenodeptr = linenodeptr->nextline;
}

fclose( stream );

linenodeptr = fileADT->line1;
while( linenodeptr->nextline !=NULL )
FileDeleteLine(linenodeptr, 1);
free(linenodeptr);

return 0;
}

main.c中如下调用:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "fileADT.h"

int main(int argc, char* argv[])
{

FileADT* fileADT=NULL;
char*string;
char*find;
char*replace;
char*filename;
int line, cutLine, pasterLine;


if (argc!=3)
{
printf ("Usage: nroffGold <input_file> <output_file>\n");
return EXIT_FAILURE;
}



FileOpen(fileADT, argv[1]);

FileClose(fileADT, argv[2]);

return 0;
}


急死了还有三天要交作业了,现在还不知道函数写得对不对.
哪位高人教我几招?感激不尽啊

搜索更多相关主题的帖子: 结点 赋值 交大 作业 
2006-04-04 22:33
快速回复:急死了还有二天要交大作业了,一个结点赋值却总是要出错!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011690 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved