So I have an assignment which I think I'm done with. The program should be able to encrypt or decrypt a text from a file using Caesarchiffer. So I first coded the whole thing in a single .c file and later split it into two .c files and one .h file and I keep getting the undefined reference to ´functionname'.
main.c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "func.h"
int main(){
int arrlen = 10, key = 1;
char * text1 = "text";
char * text2 = "text";
/*some code*/
encrypt(text1, arrlen, key, text2);
/*some code*/
decrypt(text1, arrlen, key, text2);
/*some code*/
}
func.h
#ifndef FUNC_H_INCLUDED
#define FUNC_H_INCLUDED
int encrypt(char *plainText, int arrLength, int key, char *cipherText);
int decrypt(char *plainText, int arrLength, int key, char *cipherText);
#endif
func.c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int encrypt(char *plainText, int arrLength, int key, char *cipherText){
//do stuff
}
int decrypt(char *plainText, int arrLength, int key, char *cipherText){
//do stuff
}
Only two solutions I've come up with mostly through searching is that either I've made something wrong in the main where I link to the func or I need to do something with my compiler that I don't get to work.
I'm using Code:Blocks 13.12 and GCC compiler.
Again everything works fine when I have the functions and headers in the main file so my guess is that I need to do something with the compiler. If the answer is something like
gcc main.c -o main.o -c
Give me a screenshot, can't get it to work.
Code when I had all in the main.c:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int encrypt(char *plainText, int arrLength, int key, char *cipherText);
int decrypt(char *plainText, int arrLength, int key, char *cipherText);
int main(){
int arrlen = 10, key = 1;
char * text1 = "text";
char * text2 = "text";
/*some code*/
encrypt(text1, arrlen, key, text2);
/*some code*/
decrypt(text1, arrlen, key, text2);
/*some code*/
}
int encrypt(char *plainText, int arrLength, int key, char *cipherText){
//do stuff
}
int decrypt(char *plainText, int arrLength, int key, char *cipherText){
//do stuff
}