Inclusion of functions in C using the header and additional C files

Trying to call a function from another file in C with the following code:

main.c

#include "display.h"
int main()
{
display_options();
display_price();

return 0;
}

display.h

int display_options(void);
int display_price(void);

display.c

#include <stdio.h>

int display_options()
{
printf("Welcome to the pizza parlor\n");
printf("What size pizza would you like? (in inches)");

return 0;
}

int display_price()
{
printf("Your pizza will cost 0.00\n");

return 0;
}

I created the following example here http://www.faqs.org/docs/learnc/x307.html , but it doesn’t seem to work, I get an error in code blocks 10.05 on a function called in main.c, saying "undefined link to" display_options "

+3
source share
5 answers

Code:: Blocks , display.c ( , ) . debug release , , . , IDE , . OK.

, - , | | , main.c display.c.

0

, main.c.

, :

gcc -Wall main.c display.c

:

./a.out
+3

, #include "display.h" display.c. Code:: Blocks, main.c display.c , .

+1

gcc ( .c) .

.c (.c) (.o). .

.c

gcc -c main.c
gcc -c display.c

,

gcc -o display main.o display.o

display

This may be automated using Makefile. you then create everything by simply calling make.

0
source

display.c

#include <stdio.h>

int display_options(void);
int display_price(void);
int display_options()
{
printf("Welcome to the pizza parlor\n");
printf("What size pizza would you like? (in inches)");

return 0;
}

int display_price()
{
printf("Your pizza will cost 0.00\n");

return 0;
}

Now turn on the straight display.c

in the main file instead display.h

0
source

Source: https://habr.com/ru/post/1765605/


All Articles