0

出于某种原因,我收到错误:'dlist_init':调用的参数太少。这是我的主要内容。我看不出我的 dlist_init 有什么问题,或者我在 main.dlist_init 中使用它会初始化双向链表。函数在main之后的数据文件中。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include "bool.h"
#include "Dlinklist.h"
#include "DlistElmt.h"
#include "Dlist.h"
#include "Dlistdata.h"

   /**************************************************************************************************/

int main ( int argc, char *argv[] )
{
    FILE *ifp, *ofp;
    //char outputFilename[] = argv[2];
    int *hour, *min;
    Dlist *list;
    float *temp;
    char line[15];

    if ( argc != 3 ) /* argc should be 3 for correct execution */
    {
        /* We print argv[0] assuming it is the program name */
        printf( "usage: %s filename", argv[0] );
    }
    else 
    {
        // We assume argv[1] is a filename to open
        ifp = fopen( argv[2], "r" );

        if (ifp == 0 ){

            printf("Could not open file\n");
        }

        else{

            ofp = fopen(argv[2], "w");

            dlist_init(list);

            while (fscanf(ifp, "%d:%d %f ", &hour, &min, &temp) != EOF) {
            //while( fgets(line, 100, ifp)){
                puts(line);
                fprintf(ofp, "%s", line);
                //if(sscanf("%d:%d %df", &hour, &min, &temp)==3){

                //}
            }

/**************************************************************************************************/

            /*while (fscanf(ifp, "%d:%d %df ", &hour, &min, &temp) != EOF) {
                 printf("the tempeture is  %df at %d:%d\n", temp, hour, min);
                fprintf(ofp, "the tempeture is  %df at %d:%d\n", temp, hour, min);*/
/**************************************************************************************************/

            }

fclose(ifp);
fclose(ofp);


        }

    getchar();
}

这是我的函数文件:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include "bool.h"
#include "Dlinklist.h"
#include "DlistElmt.h"
#include "Dlist.h"
#include "Dlistdata.h"

/**************************************************************************************************/

 void dlist_init(Dlist *list){

    list->size = 0;
    list->head = NULL;
    list->tail = NULL;



}

void dlist_destroy(Dlist *list){

    int *time;
    int *time2;
    float *temp;

    while (list->size > 0){
        dlist_remove(list, list->head);
    }


}

int dlist_ins_next(Dlist *list, DlistElmt *element, int *time, int *time2, float *temp1){

        DlistElmt *new_element;


        if (element == NULL && dlist_size(list) != 0)
            return -1;
        if ((new_element = (DlistElmt *)malloc(sizeof(DlistElmt))) == NULL)
            return -1;
        new_element->hour = time;
        new_element->min = time2;
        new_element->temp = temp1;
            if (dlist_size(list) == 0) {

            list->head = new_element;
            list->head->prev = NULL;
            list->head->next = NULL;
            list->tail = new_element;

        }

        else {

            new_element->next = element->next;
            new_element->prev = element;

            if(element->next == list->tail)
                list->tail = new_element;
            else
                element->next->prev = new_element;
        }

        element->next = new_element;
        list->size++;

        return 0;

    }

  int dlist_ins_prev(Dlist *list, DlistElmt *element, int *time, int *time2, float *temp1){

    DlistElmt *new_element;

    if (element == NULL && dlist_size(list) != 0)
        return -1;

    if ((new_element = (DlistElmt *)malloc(sizeof(DlistElmt))) == NULL)
        return -1;

    new_element->hour = time;
        new_element->min = time2;
        new_element->temp = temp1;

    if (dlist_size(list) == 0){

        list->head = new_element;
        list->head->prev = NULL;
        list->head->next=NULL;
        list->tail = new_element;

    }

    else{

        new_element->next = element;
        new_element->prev = element->prev;

        if(element == list->head)
            list->head = new_element;
        else
            element->prev->next = new_element;

        element->prev = new_element;

    }

    list->size++;

    return 0;
    }
 int dlist_remove(Dlist *list, DlistElmt *element){

    if (element == NULL || dlist_size(list) == 0)
        return -1;


    if (element == list->head) {

        list->head = element->next;

        if (list->head == NULL)
            list->tail = NULL;
        else
            element->next->prev = NULL;
    }

    else{

        element->prev->next = element->next;

        if (element == list->tail)
            list->tail = element->prev;
        else
            element->next->prev = element->prev;
    }

    free(element);

    list->size--;

    return 0;

  }
4

1 回答 1

0

假定函数原型是在您的头文件之一中声明的 - 它是否与您提供的声明相匹配?

于 2012-10-08T18:26:05.703 回答