Привет всем.
Какой день не могу закончить прогу на линейные списки. Программа-минимум - считать список из файла и вывести его.
main.c:
Код:
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <errno.h>
#include <stdlib.h>
#include "funcs.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
struct list *first=NULL;
if (argc == 2)
{
if (InputData(argv[1], first))
{
out(first);
}
else
printf("Error reading data");
}
else
printf("Wrong parameters: must be <Laba6.exe> <in_file.txt>");
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
funcs.c:
Код:
#define FUNCS_H
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <errno.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
struct list* InputData(char* FileName, struct list *first)
{
FILE *in_file;
struct tone new_tone;
in_file = fopen(FileName, "r");
if (in_file)
{
while (!feof(in_file))
{
fscanf(in_file, "%s", new_tone.name);
fscanf(in_file, "%d", new_tone.freq);
add(first, &new_tone);
}
}
else
return NULL;
return first;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
int add(struct list *first, void *new_data)
{
struct list *new=NULL;
new = (struct list*)malloc(sizeof(struct list));
if (new)
{
new->data = new_data;
new->next = first;
first = new;
return 0;
}
else
{
printf("Error: adding element");
return -1;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void out(struct list *first)
{
struct list *tmp=first;
while (tmp->next)
{
printf("Tone: %s\n", (*((struct tone*)tmp->data)).name);
printf("Freq: %d\n", (*((struct tone*)tmp->data)).freq);
printf("\n");
}
}
funcs.h:
Код:
#ifndef FUNCS_H
#define FUNCS_H
struct list
{
void *data;
struct list *next;
};
struct tone
{
char name[10];
int freq;
};
struct list* InputData(char* FileName, struct list *first);
int add(struct list *first, void *new_data);
void out(struct list *first);
struct list* pop_front(struct list *first, void *data);
struct list* pop_end(struct list *first, void *data);
struct list* append(struct list *a, struct list *b);
struct list* insert_sort(struct list *first);
struct list* sorted_insert(struct list *first, struct list *element);
#endif
Что мне на это пишет:
Код:
H:\Мои файлы\..progy\Моё\Лабы\3 семестр\наСи\Laba6>gcc -std=c99 -Wall -Werror -p
edantic -ggdb -o Laba6.exe main.c funcs.c
funcs.c: In function 'InputData':
funcs.c:31:14: error: storage size of 'new_tone' isn't known
funcs.c:40:4: error: implicit declaration of function 'add' [-Werror=implicit-fu
nction-declaration]
funcs.c:31:14: error: unused variable 'new_tone' [-Werror=unused-variable]
funcs.c: In function 'add':
funcs.c:54:39: error: invalid application of 'sizeof' to incomplete type 'struct
list'
funcs.c:57:12: error: dereferencing pointer to incomplete type
funcs.c:58:6: error: dereferencing pointer to incomplete type
funcs.c: In function 'out':
funcs.c:74:12: error: dereferencing pointer to incomplete type
funcs.c:76:44: error: dereferencing pointer to incomplete type
funcs.c:77:44: error: dereferencing pointer to incomplete type
cc1.exe: all warnings being treated as errors
Каждую ошибку гуглил и много раз пытался исправить, но безрезультатно.
Проблема также в том, что я не очень четко понимаю, где в многофайловом проекте надо объявлять структуры.