读书人

编译异常 求指教

发布时间: 2013-04-09 16:45:09 作者: rapoo

编译错误 求大虾指教
#include<stdio.h>
#include<ctype.h>
#include<string.h>

#define BUFFER_SIZE 50
#define MODE "r"

typedef struct _link{
char *word;
int times;
struct _link* next;
} link;


link * head;
FILE * load_file();
void read_file(FILE *);

link * create_node(char *);
link * find_node(char *);
void insert(link *);

void show();



int main(void){
FILE * fp = load_file();
read_file(fp);
show();
}

void show(){
link * tmp = head;
while(tmp != NULL){
printf("%s:%d\n",tmp->word,tmp->times);
tmp = tmp->next;
}
}


FILE * load_file(){
char filepath[BUFFER_SIZE];

fgets(filepath,BUFFER_SIZE,stdin);

FILE * fp = fopen(filepath,MODE);

if(fp == NULL){
printf("File does not exist!\n");
exit(1);
}
return fp;
}

void read_file(FILE * fp){
char buf[20];
int count = 0;
int readchar;

while((readchar = fgetc(fp)) != EOF){
if(isalpha(readchar)){
buf[count++] = readchar;
continue;
}

link * tmp = find_node(buf);
if(tmp == NULL){
tmp = create_node(buf);
insert(tmp);
}
else
tmp->times += 1;

bzero(buf,count);
count = 0;
}
}

link* create_node(char *buf){
link * tmp = (link*) malloc(sizeof(link));
char * cp = (char *)malloc(sizeof(char) * strlen(buf));
strcpy(tmp->word,cp);

return tmp;
}

link * find_node(char *word){
link * tmp = head;

while(tmp != NULL){
if(strcmp(tmp->word,word) == 0)
return tmp;
tmp = tmp->next;
}
return (link *)NULL:
}

void insert(link * node){
link * tmp = head;
head = node;
head->next = tmp;
}编译异常  求指教


[解决办法]
return (link *)NULL:

那个是冒号??
[解决办法]
return (link *)NULL: ===> return (link *)NULL;
[解决办法]
return (link *)NULL: ===> return (link *)NULL;这错误不能犯了

读书人网 >C语言

热点推荐