何らかの理由で、次のエラーが表示されます: 'dlist_init': 呼び出すには引数が少なすぎます。これが私のメインです。dlist_init または main.dlist_init での使用に問題はありませんが、二重リンク リストを初期化します。関数は、メインの後のデータ ファイルにあります。
#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;
}