| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 739 人关注过本帖
标题:『*****C程序找错*****』
只看楼主 加入收藏
剑子与剑痴
Rank: 1
等 级:新手上路
帖 子:10
专家分:4
注 册:2010-10-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:10 
『*****C程序找错*****』
这是一个头文件,代码如下:
程序代码:
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<stdio.h>


//用typedef自定义类型
typedef struct address{
        char name[6];
        char tel[18];
        struct address *next;
    }ADDR;

//宏定义函数ASk(),调用一次产生一新结点
#define ASK(p) do{ \
      p=(ADDR *)malloc(sizeof(ADDR)); \
      if(p==NULL) { printf("memory faill!");exit(); } \
    }while(0)

extern int count;

ADDR *input(ADDR *);
void display(ADDR *);
int menu_select(void);
void handle_menu(ADDR *);
ADDR *del(ADDR *);


结果如下:
程序代码:
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(20) : error C2501: 'p' : missing storage-class or type specifiers
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(20) : error C2440: 'initializing' : cannot convert from 'struct address *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(21) : error C2143: syntax error : missing ';' before 'if'
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(21) : error C2143: syntax error : missing ';' before '{'
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(21) : error C2447: missing function header (old-style formal list?)
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(22) : error C2143: syntax error : missing ';' before '}'
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(22) : error C2143: syntax error : missing ';' before '}'
d:\编程\msdev98\myprojects\vitas_2010_10_12_1\vitas2010_10_12_the1\record.h(22) : error C2143: syntax error : missing ';' before '}'

这个是我从书上打下来的,有小小改动,想了很久也不知所以,求救。。。
搜索更多相关主题的帖子: address 
2010-10-12 20:05
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:6 
源文件也发过来啊!

If You Want Something, Go Get It, Period.
2010-10-12 20:07
剑子与剑痴
Rank: 1
等 级:新手上路
帖 子:10
专家分:4
注 册:2010-10-7
收藏
得分:0 
回复 2楼 m21wo

全放上来的话可能很乱,毕竟文件有点多

http://u.



2010-10-12 20:25
剑子与剑痴
Rank: 1
等 级:新手上路
帖 子:10
专家分:4
注 册:2010-10-7
收藏
得分:0 
回复 2楼 m21wo
//宏定义函数ASk(),调用一次产生一新结点
#define ASK(p) do{p=(ADDR *)malloc(sizeof(ADDR));if(p==NULL) { printf("memory faill!");exit(-1); } }while(0)
现将头文件中的宏定义函数ASk()的标识符部分改成一行,并对其他文件中的错漏修正后,语法无错。


那就应是
#define ASK(p) do{\
p=(ADDR *)malloc(sizeof(ADDR));if(p==NULL) { printf("memory faill!");exit(-1); } \
}while(0)

中的换行符使用出错了,请问下换行符“\”的正确用法还有使用时有什么需要注意的地方。

而在语法方面改正错误后,我在运行时出现了如下语句:
程序代码:
--------------------Configuration: HHH - Win32 Debug--------------------
Compiling...
record.c
input.c
display.c
del.c
Linking...
record.obj : error LNK2001: unresolved external symbol _count
input.obj : error LNK2001: unresolved external symbol _count
display.obj : error LNK2001: unresolved external symbol _count
del.obj : error LNK2001: unresolved external symbol _count
Debug/HHH.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

HHH.exe - 1 error(s), 0 warning(s)
==========================================
error LNK2001

==========================================
我照网上的方法更改了一些设置,问题仍未解决,望高手有空指正
2010-10-12 21:37
剑子与剑痴
Rank: 1
等 级:新手上路
帖 子:10
专家分:4
注 册:2010-10-7
收藏
得分:0 
回复 2楼 m21wo
这是源文件,望高手有空指正下,谢:

http://u.
2010-10-12 21:40
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
我不知道你改的什么,我在网上下了一个!它弄的太繁琐了!我改了一下!
程序代码:
record.h
#ifndef RECORD_H
#define RECORD_H
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

//用typedef自定义类型
typedef struct address{
        char name[6];
        char tel[18];
        struct address *next;
    }ADDR;

//宏定义函数ASk(),调用一次产生一新结点
#define ASK(p) do{p=(ADDR *)malloc(sizeof(ADDR));if(p==NULL) { printf("memory faill!");exit(-1); } }while(0)



ADDR *input(ADDR *);
void display(ADDR *);
int menu_select(void);
void handle_menu(ADDR *);
ADDR *del(ADDR *);

#endif

record.c

#include"record.h"

 int count=0;
ADDR *del(ADDR *top)
{
    char choose[2],input[18];

    int cn=0;

    ADDR *old,*star;
    old=star=top;

    if(count==0)
        {
            printf("记录已经为空,结束删除操作");
            return 0 ;
        }

    printf("现在开始删除操作,选择方式\n");
    printf("1.通过代号选择\n");
    printf("2.通过电话选择\n");
    gets(choose);
    getchar();

    while(1)
        {
            cn=atoi(choose);

            if(cn!=1&&cn!=2)
                {
                     printf("输入错误,请输入1—2\n");
                     gets(choose);
                     getchar();
                }
            else break;

        }

    switch(cn)
    {
    case 1:  printf("输入代号\n");
             break;
    case 2:  printf("输入电话\n");
             break;

             }
    gets(input);
   
    for(;;)
        {
            while(cn==1&&star->name==input||cn==2&&star->tel==input)
                {
                    if(star==top)
                        top=star->next;
                    else  old->next=star->next;

                    free(star);
                    --count;
                    if(count==0)
                        {
                            ASK(top);
                            top->next=NULL;
                           
                        }
                    printf("delete...");
                    return top;
                }
            old=star;
            star=star->next;
        }
    printf("无有找到相关数据\n");
    return top;
}                         



 ADDR *input(ADDR *top)
{
    ADDR *old;
    ADDR *star;

    ASK(star);
    old=top;

    --count;
    printf("输入数据,当输入代号0时结束\n");

    for(;;)
        {
            ++count;

            printf("输入代号:\n");
            gets(star->name);
            getchar();
            if(strcmp(star->name,"0")==0)
                {
                    printf("操作结束\n");
                    break;
                }
           
            printf("输入电话:\n");
            gets(star->tel);
            getchar();
            if(strcmp(star->tel,"0")==0)
                {
                    printf("操作结束\n");
                    break;
                }

            if(count==0) top=star;

            old->next=star;
            old=star;
            ASK(star);
    }

    old->next=NULL;
    free(star);
   
    return top;

}
void  display(ADDR *top)
{
    ADDR *t=top;

    if(count==0)
        {
            printf("无有操作数据\n");
            return ;
        }
    printf("代号\t电话");
    for(;;)
        {
            if(count==0)
               return ;
           
            printf("%s\t%s\n",t->name,t->tel);

            t=t->next;
            --count;
        }
}


void handle_menu(ADDR *top)
{
    for(;;)
        {
            switch(menu_select())
            {
                case 1:  top=input(top);
                         break;
                case 2:  display(top);
                         break;
                case 3:  top=del(top);
                         break;
                case 4:  printf("停止操作!\n");
                         exit(0);
            }
    }

}



int menu_select()
{
    char ch[2];
    int i;

    printf("1. 输入数据...\n");
    printf("2. 输出数据...\n");
    printf("3. 删除数据...\n");
    printf("4. 停止操作...\n");
    printf("选择你要进行的操作:\n");
   
    for(;;)
        {
            gets(ch);
            i=atoi(ch);
           
            if(i<1||i>4)
                {
                    printf("操作错误,请确定输入数字1—4.\n");
                    printf("重新选择:\n");
                }
            else  break;

        }
    return i;


}


void  main()
{
    ADDR *top;
    ASK(top);
    top->next=NULL;
    count=0;

    handle_menu(top);

}


If You Want Something, Go Get It, Period.
2010-10-12 22:24
剑子与剑痴
Rank: 1
等 级:新手上路
帖 子:10
专家分:4
注 册:2010-10-7
收藏
得分:0 
嗯,我书上的头文件也是
程序代码:
#ifndef RECORD_H
#define RECORD_H
。。。。。。。
。。。。。。。
#endif
这种形式的,我看了觉得多余就去掉了。
而关于刚才我修改后了现的count没定义的情况(record.obj : error LNK2001: unresolved external symbol _count),
我将头文件中的extern int count中的extern去掉后运行通过了,这个觉得很奇怪

2010-10-12 23:04
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
全局变量可写可不写在头文件中!我在头文件中就没写!


If You Want Something, Go Get It, Period.
2010-10-13 12:36
墨菲斯
Rank: 2
等 级:论坛游民
帖 子:8
专家分:14
注 册:2010-10-12
收藏
得分:6 
楼上的牛!!!!!
2010-10-13 14:10
以中
Rank: 3Rank: 3
来 自:长沙
等 级:论坛游侠
帖 子:108
专家分:129
注 册:2010-4-13
收藏
得分:6 
我查了一下MSDN Library,有点奇怪:
Routine   Required Header
malloc    <stdlib.h> and <malloc.h>
怎么要两个头文件。
#include <stdlib.h>         /* For _MAX_PATH definition */
#include <stdio.h>
#include <malloc.h>

void main( void )
{
   char *string;

   /* Allocate space for a path name */
   string = malloc( _MAX_PATH );

   // In a C++ file, explicitly cast malloc's return.  For example,
   // string = (char *)malloc( _MAX_PATH );

   if( string == NULL )
      printf( "Insufficient memory available\n" );
   else
   {
      printf( "Memory space allocated for path name\n" );
      free( string );
      printf( "Memory freed\n" );
   }
}

道之所存,师之所存。
2010-10-13 15:36
快速回复:『*****C程序找错*****』
数据加载中...
 
   



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

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