佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 782|回复: 5

HELP!!! linked list problem

[复制链接]
cheong_yuen 该用户已被删除
发表于 25-12-2005 09:04 AM | 显示全部楼层 |阅读模式
This is my code but when i compile it got problem in module file, can anyone help me correct it thk.................

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/* student2.c : The Module file */

#include "student.h"

static NODE *head_ptr = NULL;
/**
** main_interface()
**/
void main_interface(int ch)
{
        switch(ch){

        case 'a':

                list_node_add();
                break;

        case 'd':

                if (!list_node_delete())
                        list_node_print();
                break;

        case 'p':

                list_node_print();

                break;

        default:
                break;

        }

}
/**
** list_node_create()
**/
NODE *list_node_create(void)
{
        NODE *ptr;

        if((ptr=(NODE *)malloc(sizeof(NODE))) == NULL)
                ErrorExit("malloc() failed.\n");

        ptr ->next_ptr = NULL; /* set the next pointer to null */
        ptr ->id = 0;  /* initialization */
        return ptr;

}
/**
** list_node_add()
**/
void list_node_add(void)
{
        NODE *new_ptr, *ptr;

        new_ptr = list_node_create();
        printf("Enter the Student Name and ID,\n");
        printf("Enter the Student CGPA and GRADE : ");
        scanf("%s%ld%f%s",new_ptr ->name, &new_ptr ->id,&new_ptr ->cgpa,new_ptr ->grade);

        if (head_ptr == NULL){
                head_ptr = new_ptr;
        }
        else{
                /*find the last node in the list */
                for(ptr=head_ptr;
                    ptr ->next_ptr !=NULL;
                        ptr=ptr ->next_ptr)
                ;/* doing nothing here */
                /* link to the last node */
                ptr ->next_ptr = new_ptr;

        }

}
/**
** list_node_delete()
**/
int list_node_delete(void)
{
        NODE *ptr, *ptr_saved;
        unsigned long id;
        int deleted = 0;
        int reval = 0;

        if (head_ptr == NULL){
                printf("Sorry, nothing to delete.\n");
                reval = 1;
        }
        else
        {
                printf("Enter the student ID: ");
                scanf("%ld",&id);

                if(head_ptr ->id == id){
                        ptr_saved = head_ptr ->next_ptr;
                        free(head_ptr);
                        head_ptr = ptr_saved;
                        if (head_ptr == NULL){
                                printf("All node have been deleted.\n");
                                reval = 1;
                        }
                }else{
                        for (ptr=head_ptr;
                             ptr->next_ptr != NULL;
                                 ptr=ptr->next_ptr){
                Error->                           if  (ptr->next_ptr->id == id){
                Error->                           ptr_saved = ptr->next_ptr->next_ptr;

                                        free(ptr->next_ptr);
                                        ptr->next_ptr = ptr_saved;
                                        deleted = 1;
                                        break;
                                }
                        }
                        if (!deleted){
                                printf("Can not find the student ID.\n");
                        }
                }
        }
        return reval;
}
/**
** list_node_print()
**/
void list_node_print(void)
{
        NODE *ptr;

        if (head_ptr == NULL){
                printf("Nothing to display.\n");
        }else{
                printf("The content of the linked list:\n");
                for (ptr = head_ptr;ptr ->next_ptr != NULL;ptr = ptr ->next_ptr){
                        printf("%s:ID:%d,CGPA:%.2f,GRADE:%s -> \n",ptr -> name,ptr ->id,ptr -> cgpa,ptr ->grade);
                }
                printf("%s:ID:%d,CGPA:%.2f,GRADE:%s  ->|",ptr -> name,ptr ->id,ptr -> cgpa,ptr ->grade);
                printf("\n");
        }
}
/**
** list_node_free()
**/
void list_node_free()
{
        NODE *ptr, *ptr_saved;

        for (ptr=head_ptr; ptr != NULL; ){
                ptr_saved = ptr ->next_ptr;
                free(ptr);
                ptr = ptr_saved;
        }
        free(ptr);
}
/**
** ErrorExit()
**/
void ErrorExit(char *str)
{
        printf("%s\n",str);
        exit(ERR_FLAG);
}
/**
** Display()
**/
void Display(void)

{


        printf("\t****************************************************\n");
        printf("\t\t   WELCOME TO CLASS RECORD SYSTEM\n");
        printf("\t****************************************************\n");
    printf("\t\t***************************************\n\n");
        printf("\t\tGrade                        Grade Point\n");
        printf(" \t\tA                             4.00\n");
        printf(" \t\tA-                            3.67\n");
        printf(" \t\tB+                            3.33\n");
        printf(" \t\tB                             3.00\n");
        printf(" \t\tB-                            2.67\n");
        printf(" \t\tC+                            2.33\n");
        printf(" \t\tC                             2.00\n");
        printf(" \t\tC-                            1.67\n");
        printf(" \t\tC                             1.33\n");
        printf(" \t\tC-                            1.67\n");
        printf(" \t\tD+                            1.33\n");
        printf(" \t\tD                             1.00\n");
        printf(" \t\tE                             0.00\n\n");
        printf("\t\t***************************************\n\n");

}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

/* student1.c : The drive file */

#include "student.h"  /* include header file */

main(void)
{
        int ch;
     Display();
        printf("Enter a for adding, d for deleting,\n");
    printf("p for displaying, and q for quit:\n");
        while ((ch=getchar())!= 'q') {

                main_interface(ch);  /* process input from the user */

        }

        list_node_free();
    printf("\nBye!\n");

        return 0;

}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

/*student.h : the header file */

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

#ifndef LNK_LIST_H
#define LNK_LIST_H
#define ERR_FLAG 1
#define MAX_LEN 16

struct lnk_list_struct
{
        char name[MAX_LEN];
        unsigned long id;
        float cgpa;
        char grade[10];
        struct lnk_list__struct *next_ptr;
};

typedef struct lnk_list_struct NODE;

NODE *list_node_create(void);
void list_node_add(void);
int list_node_delete(void);
void list_node_print(void);
void list_node_free(void);
void ErrorExit(char *);
void main_interface(int);
void Display(void);

#endif /* for LNK_LIST_H */

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

--------------------Configuration: student2 - Win32 Debug--------------------
Compiling...
student2.c
c:\documents and settings\user\desktop\latest\student2.c(70) : warning C4133: '=' : incompatible types - from 'struct lnk_list__struct *' to 'struct lnk_list_struct *'
c:\documents and settings\user\desktop\latest\student2.c(73) : warning C4133: '=' : incompatible types - from 'struct lnk_list_struct *' to 'struct lnk_list__struct *'
c:\documents and settings\user\desktop\latest\student2.c(98) : warning C4133: '=' : incompatible types - from 'struct lnk_list__struct *' to 'struct lnk_list_struct *'
c:\documents and settings\user\desktop\latest\student2.c(108) : warning C4133: '=' : incompatible types - from 'struct lnk_list__struct *' to 'struct lnk_list_struct *'
c:\documents and settings\user\desktop\latest\student2.c(109) : error C2037: left of 'id' specifies undefined struct/union 'lnk_list__struct'
c:\documents and settings\user\desktop\latest\student2.c(110) : error C2037: left of 'next_ptr' specifies undefined struct/union 'lnk_list__struct'
c:\documents and settings\user\desktop\latest\student2.c(112) : warning C4133: '=' : incompatible types - from 'struct lnk_list_struct *' to 'struct lnk_list__struct *'
c:\documents and settings\user\desktop\latest\student2.c(159) : warning C4133: '=' : incompatible types - from 'struct lnk_list__struct *' to 'struct lnk_list_struct *'
c:\documents and settings\user\desktop\latest\student2.c(174) : warning C4133: '=' : incompatible types - from 'struct lnk_list__struct *' to 'struct lnk_list_struct *'
Error executing cl.exe.

student2.obj - 2 error(s), 7 warning(s)

[ 本帖最后由 cheong_yuen 于 25-12-2005 10:54 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 25-12-2005 09:39 PM | 显示全部楼层
omg... haha

不是不会pointer...但是。。。很懒打字

....连compiler message也不放出来。。。

不同compiler,规格也有少许不同的le...

懒人留言
回复

使用道具 举报

发表于 25-12-2005 09:41 PM | 显示全部楼层
别生气哦

arigato
回复

使用道具 举报

cheong_yuen 该用户已被删除
 楼主| 发表于 25-12-2005 10:58 PM | 显示全部楼层
Sorry ........forgot
回复

使用道具 举报

发表于 26-12-2005 08:53 AM | 显示全部楼层
这部分出错。

struct lnk_list_struct
{
        char name[MAX_LEN];
        unsigned long id;
        float cgpa;
        char grade[10];
        struct lnk_list__struct *next_ptr; << 你错在这里
};

struct lnk_list__struct *next_ptr; << 你打了两个underscore...
struct lnk_list_struct *next_ptr;  << 看到分别吗?
回复

使用道具 举报

cheong_yuen 该用户已被删除
 楼主| 发表于 26-12-2005 11:10 AM | 显示全部楼层
thanks o1j2m3
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 4-3-2025 04:24 PM , Processed in 0.409084 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表