免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2178 | 回复: 8
打印 上一主题 下一主题

用纯c写的在vc下运行通过了,在unix下出现错误! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-09-18 14:39 |只看该作者 |倒序浏览
运行提示错误:
test.c: In function `main':
test.c:42: `filelist' undeclared (first use in this function)
test.c:42: (Each undeclared identifier is reported only once
test.c:42: for each function it appears in.)
test.c:102: `fileNode' undeclared (first use in t his function)
test.c:138:12: warning: no newline at end of file
请各位大侠帮帮忙,急用!!!
我的程序如下:
#include<stdio.h>;
#include<string.h>;
#include<malloc.h>;
#include<stdlib.h>;
//#include"err_exit.h"
#define BUF_SIZE 40
#define FILE_SIZE sizeof (filelist)
#define Node_SIZE sizeof (fileNode)
#define A 30
#define B 10
#define C 30
#define D 10
#define E 20
struct fileNode
{         
        char   finame[A+1];
        char   intercode[B+1];
        char   ftime[C+1];
        char   fsize[D+1];
        char   recordCount[E+1];
};
struct filelist   
{                           
        struct fileNode  *PNode;//指向一条记录
        struct filelist *next;  //next
};
int main(int argc,char *argv[])
{      
        FILE   *dat;
        char   buf1[BUF_SIZE],buf2[BUF_SIZE],buf3[BUF_SIZE],buf4[BUF_SIZE],buf5[BUF_SIZE];
        int    i=0;
        int flag=0;
        char   c;
        struct filelist *app,*head,*Temp;
        struct fileNode *TempLink;
        /*检查参数*/
        /*if (argc!=2)
        {
                 printf("usage:a.out<filepathname>;\n";
                 exit(1);
               };*/
               head=app=(struct filelist *)malloc(FILE_SIZE);//分配链表空间
        
               if((dat=fopen("format.avl","r+")==NULL)
                //err_exit("open failed.\n";
                {printf("%s","open failed.\n";
                 exit(1);
                };
        //printf("%s",test.\n";
        c=fgetc(dat);       
        while(!feof(dat))
        {
           i=0;
          flag=0;//如果为空,则不读
          while ((c!=',')&&(c!='\n'))//读取第一个字段
          {
                   buf1=c;
           i++;
           c=fgetc(dat);
                   flag=1;
           };
                  buf1='\0';
          c=fgetc(dat);//读取下一个字符
                  i=0;
          while ((c!=',')&&(c!='\n')&&flag)//读取第二个字段
          {
                   buf2=c;
           i++;
           c=fgetc(dat);       
           };
                  buf2='\0';
           c=fgetc(dat); //读取下一个字符
           i=0;
           while ((c!=',')&&(c!='\n')&&flag)//读取第三个字段
          {
                   buf3=c;
           i++;
           c=fgetc(dat);       
           };
                  buf3='\0';
           c=fgetc(dat);//读取下一个字符
                   i=0;
          while ((c!=',')&&(c!='\n')&&flag)//读取第四个字段/
          {
                   buf4=c;
           i++;
           c=fgetc(dat);       
           };
                  buf4='\0';
           c=fgetc(dat);//读取下一个字符
                   i=0;
           while ((c!='\n')&&flag)//读取第五个字段
          {
           buf5=c;
           i++;
           c=fgetc(dat);       
           };   
           buf5='\0';             
          if((c=='\n')&&flag)//在有换行符时取出当前行,然后根据根据输入文件的属性长度取出属性值         
          {     
                    Temp=(struct filelist *)malloc(FILE_SIZE);//分配链表空间
                TempLink=(struct fileNode *)malloc(Node_SIZE);
                    for(i=0;i<A;i++)
                      (*TempLink).finame=buf1;
                                //(*TempLink).finame='\0';
                for(i=0;i<B;i++)
                  (*TempLink).intercode=buf2;
                                //(*TempLink).intercode='\0';
                for(i=0;i<C;i++)
                  (*TempLink).ftime=buf3;
                                //(*TempLink).ftime='\0';
                for(i=0;i<D;i++)
                  (*TempLink).fsize=buf4;
                                //(*TempLink).fsize='\0';
                for(i=0;i<E;i++)
                  (*TempLink).recordCount=buf5;
                                //(*TempLink).fsize='\0';
                    Temp->;next=NULL;
                Temp->Node=TempLink;
                head->;next=Temp;
                head=head->;next ;
             }//end if
                c=fgetc(dat);
                            
        }//end while
  head=app->;next;
        //测试链表中的数据,将其在屏幕上全部显示出来
        while(head!=NULL)
        {
                printf("%s\n",(head->Node)->;finame);                       
                printf("%s\n",(head->Node)->;intercode);
                printf("%s\n",(head->Node)->;ftime);
                printf("%s\n",(head->Node)->;fsize);
                printf("%s\n",(head->Node)->;recordCount);
                head=head->;next;
        };
return 1;
}//end while

论坛徽章:
0
2 [报告]
发表于 2003-09-18 15:01 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

改成这样   
typedef struct fileNode
{
char finame[A+1];
char intercode[B+1];
char ftime[C+1];
char fsize[D+1];
char recordCount[E+1];
}fileNode;
typedef struct filelist
{
struct fileNode *PNode;//指向一条记录
struct filelist *next; //next
}filelist;

论坛徽章:
0
3 [报告]
发表于 2003-09-18 15:39 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

用了你的方法编译通过了,非常感谢,可是接着我又发现printf函数根本没执行根本没执行,屏幕打印不出来,这又是怎么回事?
语句: printf("usage:a.out<filepathname>;\n";

论坛徽章:
0
4 [报告]
发表于 2003-09-18 16:36 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

/*if (argc!=2)
{
printf("usage:a.out<filepathname>;\n";
exit(1);
};*/

论坛徽章:
0
5 [报告]
发表于 2003-09-18 16:54 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

程序运行时出现Segmentation fault(coredump)
可是我在vc下运行得好好的 啊

论坛徽章:
0
6 [报告]
发表于 2003-09-18 17:09 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

原帖由 "yanyl" 发表:
程序运行时出现Segmentation fault(coredump)
可是我在vc下运行得好好的 啊
    出现内存分段故障的一般情况下是内存指针越界的原因

论坛徽章:
0
7 [报告]
发表于 2003-09-18 17:11 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

http://chinaunix.net/forum/viewtopic.php?t=133606&highlight=yuxq

论坛徽章:
0
8 [报告]
发表于 2003-09-18 18:40 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

各位看看哪里有可能出错,我找了很久了,找不出原因
我想可能是文件读完后出错,可是我不知道为什么!
各位帮帮忙,看一下吧!

论坛徽章:
0
9 [报告]
发表于 2003-09-18 19:46 |只看该作者

用纯c写的在vc下运行通过了,在unix下出现错误!

搞定了,谢谢各位了,特别感谢yuxq
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP