| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5372 人关注过本帖
标题:寻求error LNK2001: unresolved external symbol _main解决办法
只看楼主 加入收藏
huangch
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:62
专家分:0
注 册:2008-7-21
收藏
 问题点数:0 回复次数:8 
寻求error LNK2001: unresolved external symbol _main解决办法
向各位大侠请教了,我的程序是这样的:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

#define MAXWORD 100
#define BUFSIZE 1000
#define NDISTINCT 1000

int getch(void);
void ungetch(int c);
int comment(void);
int getword(char *word, int lim);
struct tnode *talloc(void);
char *strdup(char *s);
struct tnode *addtree(struct tnode *p, char *w);
void treestore(struct tnode *p);
void sortlist();

struct tnode *list[NDISTINCT];
int ntn = 0;

char buf[BUFSIZE];   
int bufp = 0;         

struct tnode {              
    char *word;               
    int count;               
    struct tnode *left;      
    struct tnode *right;      
};

main()
{
    struct tnode *root;
    char word[MAXWORD];
    int i;

    root = NULL;
    while (getword(word, MAXWORD) != EOF)
        if (isalpha(word[0]))
            root = addtree(root, word);
    treestore(root);
    sortlist();
    for (i=0; i<ntn; i++)
        printf("%2d:%20s\n",list[i]->count, list[i]->word);
    return 0;
}
       

int getch(void)
{
    if (bufp > 0)
        return buf[--bufp];
    else
        return getchar();
}

void ungetch(int c)
{
    if (bufp >= BUFSIZE)
        printf("ungetch: too many characters\n");
    else
        buf[bufp++] = c;
}

int comment(void)
{
    int c;
    while ((c = getch()) != EOF)
        if (c == '*')
            if ((c = getch()) == '/')
                break;
            else
                ungetch(c);
    return c;
}

int getword(char *word, int lim)
{
    int c;
    char *w = word;

    while (isspace(c = getch()))
        ;
    if (c != EOF)
        *w++ = c;
    if (!isalpha(c)) {
        *w = '\0';
        return c;
    }
    for ( ; --lim > 0; w++)
        if (!isalnum(*w = getch())) {
            ungetch(*w);
            break;
        }
    *w = '\0';
    return word[0];
}

struct tnode *talloc(void)
{
    return (struct tnode *) malloc(sizeof(struct tnode));
}

char *strdup(char *s)
{
    char *p;

    p = (char *) malloc(strlen(s)+1);
    if (p != NULL)
        strcpy(p, s);
    return p;
}

struct tnode *addtree(struct tnode *p, char *w)
{
    int cond;

    if (p == NULL) {
        p = talloc();
        p->word = strdup(w);
        p->count = 1;
        p->left = p->right = NULL;
    } else if ((cond = strcmp(w, p->word)) == 0)
        p->count++;
    else if (cond < 0)
        p->left = addtree(p->left, w);
    else
        p->right = addtree(p->right, w);
    return p;
}

void treesorte(struct tnode *p)
{
    if (p != NULL) {
        treesorte(p->left);
        printf("%4d %s\n", p->count, p->word);
        treesorte(p->right);
    }
}

void sortlist()
{
    int gap, i, j;
    struct tnode *temp;

    for (gap = ntn/2; gap > 0; gap /= 2)
        for (i=gap; i<ntn; i++)
            for (j=i-gap; j>=0; j-=gap) {
                if ((list[j]->count) >= (list[j+gap]->count))
                    break;
                temp = list[j+gap];
                list[j] = list[j+gap];
                list[j+gap] = temp;
            }
}
目的在于想根据单词的出现频率按降序打印输入的各个不同单词,并在每个单词的前面标上它的出现次数。
可vc编译器总是出现:
error LNK2001: unresolved external symbol "void __cdecl treestore(struct tnode *)" (?treestore@@YAXPAUtnode@@@Z)与
fatal error LNK1120: 1 unresolved externals
上网找了其他资料,但并不能解决,现在莱鸟想向高手请教了!
搜索更多相关主题的帖子: symbol main external unresolved 
2008-08-11 17:01
爱喝牛奶的猫咪
Rank: 1
来 自:QQ群46520219
等 级:禁止访问
帖 子:513
专家分:0
注 册:2008-6-16
收藏
得分:0 
你工程建错了


[color=white]<" border="0" />>
2008-08-11 17:23
huangch
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:62
专家分:0
注 册:2008-7-21
收藏
得分:0 
那请问怎么弄??
2008-08-11 18:34
huangch
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:62
专家分:0
注 册:2008-7-21
收藏
得分:0 
我顶!
2008-08-11 19:01
woshiyun
Rank: 1
等 级:新手上路
威 望:2
帖 子:348
专家分:0
注 册:2008-6-16
收藏
得分:0 
2#真搞,难道你编一个hello也要建个工程?

LZ,你的void treestore(struct tnode *p);没有定义,定义一个就好了,不知道怎么实现就定义一个空函数,至少编译能过。

void treestore(struct tnode *p)
{
}
2008-08-11 19:04
huangch
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:62
专家分:0
注 册:2008-7-21
收藏
得分:0 
回复 5# woshiyun 的帖子
有啊!怎么会没有?
int getch(void);
void ungetch(int c);
int comment(void);
int getword(char *word, int lim);
struct tnode *talloc(void);
char *strdup(char *s);
struct tnode *addtree(struct tnode *p, char *w);
void treestore(struct tnode *p);
void sortlist();
2008-08-11 19:08
woshiyun
Rank: 1
等 级:新手上路
威 望:2
帖 子:348
专家分:0
注 册:2008-6-16
收藏
得分:0 
[bo][un]huangch[/un] 在 2008-8-11 19:08 的发言:[/bo]

有啊!怎么会没有?
int getch(void);
void ungetch(int c);
int comment(void);
int getword(char *word, int lim);
struct tnode *talloc(void);
char *strdup(char *s);
struct tnode *addtree(struct tno ...

这个叫申明,申明了还要实现。这个程序不是你写的吧
2008-08-11 19:15
huangch
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:62
专家分:0
注 册:2008-7-21
收藏
得分:0 
谢谢!我对    struct tnode *root;进行定义了!不过,我很奇怪?我第一次遇到函数是要定义的;为什么要定义呢?其它函数怎么不用啊?
2008-08-11 19:53
woshiyun
Rank: 1
等 级:新手上路
威 望:2
帖 子:348
专家分:0
注 册:2008-6-16
收藏
得分:0 
不知道你在说什么,
也不知道你明白我刚才说什么了没有。
把你的程序改好的给你贴上,自己比较吧。

注意:是没有编译错误,运行错误自己解决啊。

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

#define MAXWORD 100
#define BUFSIZE 1000
#define NDISTINCT 1000

int getch(void);
void ungetch(int c);
int comment(void);
int getword(char *word, int lim);
struct tnode *talloc(void);
char *strdup(char *s);
struct tnode *addtree(struct tnode *p, char *w);
void treestore(struct tnode *p);
void sortlist();

struct tnode *list[NDISTINCT];
int ntn = 0;

char buf[BUFSIZE];   
int bufp = 0;         

struct tnode {              
    char *word;               
    int count;               
    struct tnode *left;      
    struct tnode *right;      
};

main()
{
    struct tnode *root;
    char word[MAXWORD];
    int i;

    root = NULL;
    while (getword(word, MAXWORD) != EOF)
        if (isalpha(word[0]))
            root = addtree(root, word);
    treestore(root);
    sortlist();
    for (i=0; i<ntn; i++)
        printf("%2d:%20s\n",list[i]->count, list[i]->word);
    return 0;
}
      

int getch(void)
{
    if (bufp > 0)
        return buf[--bufp];
    else
        return getchar();
}

void ungetch(int c)
{
    if (bufp >= BUFSIZE)
        printf("ungetch: too many characters\n");
    else
        buf[bufp++] = c;
}

int comment(void)
{
    int c;
    while ((c = getch()) != EOF)
        if (c == '*')
            if ((c = getch()) == '/')
                break;
            else
                ungetch(c);
    return c;
}

int getword(char *word, int lim)
{
    int c;
    char *w = word;

    while (isspace(c = getch()))
        ;
    if (c != EOF)
        *w++ = c;
    if (!isalpha(c)) {
        *w = '\0';
        return c;
    }
    for ( ; --lim > 0; w++)
        if (!isalnum(*w = getch())) {
            ungetch(*w);
            break;
        }
    *w = '\0';
    return word[0];
}

struct tnode *talloc(void)
{
    return (struct tnode *) malloc(sizeof(struct tnode));
}

char *strdup(char *s)
{
    char *p;

    p = (char *) malloc(strlen(s)+1);
    if (p != NULL)
        strcpy(p, s);
    return p;
}

struct tnode *addtree(struct tnode *p, char *w)
{
    int cond;

    if (p == NULL) {
        p = talloc();
        p->word = strdup(w);
        p->count = 1;
        p->left = p->right = NULL;
    } else if ((cond = strcmp(w, p->word)) == 0)
        p->count++;
    else if (cond < 0)
        p->left = addtree(p->left, w);
    else
        p->right = addtree(p->right, w);
    return p;
}

void treesorte(struct tnode *p)
{
    if (p != NULL) {
        treesorte(p->left);
        printf("%4d %s\n", p->count, p->word);
        treesorte(p->right);
    }
}

void sortlist()
{
    int gap, i, j;
    struct tnode *temp;

    for (gap = ntn/2; gap > 0; gap /= 2)
        for (i=gap; i<ntn; i++)
            for (j=i-gap; j>=0; j-=gap) {
                if ((list[j]->count) >= (list[j+gap]->count))
                    break;
                temp = list[j+gap];
                list[j] = list[j+gap];
                list[j+gap] = temp;
            }
}

void treestore(struct tnode *p)
{
}
2008-08-11 19:59
快速回复:寻求error LNK2001: unresolved external symbol _main解决办法
数据加载中...
 
   



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

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