记事本程序只可以打开同目录下的文件,打开别的文件出现CXX0017错误

jundaxia 2010-10-20 07:03:53
记事本程序只可以打开同目录下的文件,出错的代码部分如下,标红的就是错误语句,求各位找找原因





#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define NULL 0
#define MAX 100

typedef struct lnode
{
char date[MAX]; //存放数据
struct lnode * prior; //前驱
struct lnode * next; //后继
int number ; //记录一个节点的字符数!如果是头节点就记录他的节点个数
int quese ; //记录节点在链表中的位置
}lnodetype;

char a;
lnodetype * l; //设置两个全局变量,分别是头节点指针和尾节点指针
lnodetype * end;
char *q="cls";

void pa();
exitunsave(lnodetype ** l, lnodetype ** end) ;
quitandsave( lnodetype ** l , lnodetype ** end ) ;
int add(lnodetype ** l,lnodetype ** end);
int searchstr(lnodetype ** l , lnodetype ** end);
void f();
int search (lnodetype ** l, lnodetype ** end );

//************(1)这个函数用来建立链表**************//
iniatelist (lnodetype ** l , lnodetype ** end)
{
(*l) = (lnodetype *)malloc (sizeof (lnodetype) ) ;
if ( (*l) == NULL )
{
printf ("没有只够的内存空间!程序即将退出!");
return 0;
}
(*l)->prior = (*l)->next = NULL ; //这是双链表
(*l)->number = (*l)->quese = 0; //节点数为零
(*end) = (*l) ; //头尾节点统一
return 0;
}

//**********(2)这个函数是用来建立节点,并且插入元素的**********//
link(lnodetype ** l, lnodetype ** end)
{
lnodetype *s ;
s = (lnodetype *)malloc ( sizeof (lnodetype) ) ;
if ( s == NULL )
{
printf ("内存空间不够,程序即将退出!") ;
return 0 ;
}
(*end)->next = s ; //把s节点插入(end)节点后面
s->prior = (*end) ;
(*end) = (*end)->next ;
(*l)->number++ ; //增加一个节点,头节点的number就加1
s->quese = (*l)->number ; //这个是记录节点在链表中的位置
printf ("%d行", s->quese ) ; //这个是节点在整个链表中的位置

while(static int a=1){getchar();a=0;}//因为回车占用字符而使用,无意义
gets(s->date) ; //一行的信息
s -> number = strlen(s->date) ; //储存该节点的长度
return 0 ;
}

//***********(3)从文件中导入相关信息存入链表************//
loadtaxt( lnodetype ** l , lnodetype ** end )
{
FILE * fp ;
char ch ;
char* file=(char*)malloc(sizeof(char)*MAX);
int i = 0 ,k=0,j=0,cout=0;;
char * q = "cls" ;
iniatelist ( &(*l) , &(*end)) ;
f();

printf("请输入要打开的文件名(含路径):\n");
gets(file);
if ( ( fp = fopen( file, "r+" ) ) == NULL )
{
printf ("文件不能打开!\n") ;
return 0 ;
}
ch = fgetc ( fp ) ;
while ( ch != '@' )
{
j++;
lnodetype *s ;
s = (lnodetype *)malloc ( sizeof (lnodetype) ) ;
if ( s == NULL )
{
printf ( "内存空间不够,程序即将退出!" ) ;
return 0 ;
}
(*end)->next = s ;
s->prior = (*end) ;
(*end) = (*end)->next ;
(*l)->number++ ;
s->quese = (*l)->number ;
while ( ch != '\n' )
{

s->date[i] = ch ; ch = fgetc (fp) ;
i++ ;
}
i = 0;
(*end)->date[i] = '\0' ; //注意在节点的最好加上这个,以让退出保存功能函数知道此节点已结束
k++ ;
if(!(k%10))
i = 0 ;
ch = fgetc ( fp ) ;
}
fclose(fp);
return 1;
}
...全文
81 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jundaxia 2010-10-21
  • 打赏
  • 举报
回复
谁帮忙看看呀
jundaxia 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ayw215 的回复:]
单步调吧
[/Quote]

你帮忙看看吧。多谢
jundaxia 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ayw215 的回复:]
中文路径的问题?
\\的问题?
调试下看看吧
[/Quote]

不是中文路径,\\也没问题,打开不存在的文件也能正常显示没这个文件,调试只有这一个错误
ayw215 2010-10-20
  • 打赏
  • 举报
回复
中文路径的问题?
\\的问题?
调试下看看吧

69,373

社区成员

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

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