由于某种原因,我收到错误:'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;
}
答案 0 :(得分:0)
假设函数原型在您的一个头文件中声明 - 它是否与您提供的声明匹配?