Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.01.2014, 19:12   #1
Григоренко Степан
Пользователь
 
Регистрация: 05.05.2011
Сообщений: 35
По умолчанию Си структуры в многофайловых проектах

Привет всем.
Какой день не могу закончить прогу на линейные списки. Программа-минимум - считать список из файла и вывести его.

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
Каждую ошибку гуглил и много раз пытался исправить, но безрезультатно.
Проблема также в том, что я не очень четко понимаю, где в многофайловом проекте надо объявлять структуры.
Григоренко Степан вне форума Ответить с цитированием
Старый 14.01.2014, 20:34   #2
waleri
Старожил
 
Регистрация: 13.07.2012
Сообщений: 6,331
По умолчанию

А где у вас #include "funcs.h"?
waleri вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Перечисления в CLR проектах cojuer Visual C++ 1 30.07.2013 09:45
JavaFX в рабочих проектах. spamer Общие вопросы по Java, Java SE, Kotlin 2 28.12.2012 16:49
Участие в интересных проектах Blade Свободное общение 16 23.02.2009 15:39
Мнение о проектах MAKEDON Свободное общение 3 18.08.2008 11:52