I am in the process of exploring the C programming language and have started to learn about header files.
I am working with three different files in my program. One header file and two source files:
encrypt.h
void encrypt(char *message);
encrypt.c
#include "encrypt.h"
void encrypt(char *message)
{
while(*message)
{
*message = *message ^ 31;
message++;
}
}
main.c
#include <stdio.h>
#include "encrypt.h"
int main()
{
char myMessage[] = "Hello";
printf("Regular message: %s\n", myMessage);
encrypt(myMessage);
printf("Encrypted message: %s\n", myMessage);
return 0;
}
The first line in the encrypt.c file is the #include statement:
#include "encrypt.h"
My question is why is this line necessary inside of this file. I was reading how the #include directive has a copy/paste functionality and inside of the main.c file I can see how this approach would support forward declaration for the encrypt function; however, inside of the encrypt.c file, it would seem that forward declaration of the function is not necessary, and was wondering what was the purpose of using the include directive in this situation?
I apologize if this question has been asked elsewhere and will mark as duplicate as required. Thank you for the clarification.