I'm making a structure about animal and other functions to control it. When all code from other files was in one file it was working good, but when I decided to set code to other files I'm getting these errors:
d:/programms/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.0.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\yuriy\AppData\Local\Temp\ccAi1tOR.o:main.c:(.text+0x2a): undefined reference to `new_animal'
d:/programms/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.0.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\yuriy\AppData\Local\Temp\ccAi1tOR.o:main.c:(.text+0x36): undefined reference to `animal_info'
collect2.exe: error: ld returned 1 exit status
main.c
#include <stdio.h>
#include <stdlib.h>
#include "animal.h"
int main() {
animal jack = new_animal("jack", 23, 2.4f);
animal_info(&jack);
return 0;
}
animal.h
#pragma once
typedef struct animal {
char name[25];
int age;
float happiness;
} animal;
struct animal new_animal(char name[25], int age, float happiness);
void animal_info(struct animal *an);
animal.c
#include <stdio.h>
#include <stdlib.h>
#include "animal.h"
#include "charfunc.h"
struct animal new_animal(char name[25], int age, float happiness) {
struct animal *an = malloc(sizeof(struct animal));
copy_paste(name, an->name);
an->age = age;
an->happiness = happiness;
return *an;
free(an);
}
void animal_info(struct animal *an) {
printf("ANIMAL INFO:\n");
printf(" name -> %s\n", an->name);
printf(" age -> %d\n", an->age);
printf(" happiness -> %f\n", an->happiness);
}
charfunc.h
#pragma once
void copy_paste(const char* from, char* to);
charfunc.c
#include <stdio.h>
#include <stdlib.h>
#include "charfunc.h"
void copy_paste(const char* from, char* to) {
int i = 0;
for (i; from[i]; i++)
{
to[i] = from[i];
}
to[i] = 0;
}