I'm new to C and need some help figuring out this error.I've only just started coding my main function but decided to compile it to test it; I get this error.
Undefined first referenced
symbol in file
simpleEncrypt lab2.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Here is my code so far:
encrypt.h
Code:
/*!
* Replaces each letter in the character array wih its next lexicographical
* letter.
* Sample: "Good" becomes "Hppe"
!*/
char simpleEncrypt(char input[20]);
/*!
* Add to each letter with its index in the given input.
* Sample: "Good" becomes "Gpqg"
*
!*/
char mediumEncrypt(char input[20]);
/*!
* Add to each letter with the square of its index in the given
* input.
* Sample: "Good" becomes "Gpsm"
!*/
char ultraEncrypt(char input[20]);
encrypt.c
Code:
#include"encrypt.h"
#include<stdio.h>
char simpleEncrypt(char input[20])
{
int i, len = strlen(input);
//for loop goes through all the characters in input and adds 1 to the ascii value
//of each character
for(i = 0;i < len; i++)
{
input[i] = (int)input[i];
input[i]++;
//if the character is now ascii value 91 then we must loop around to ascii
//value 65. In other words goes from Z to A.
if(input[i] == 91)
{
input[i] = 65;
}
//if the character is now ascii value 123 then we must loop around to ascii
//value 97. In other words goes from z to a.
if(input[i] == 123)
{
input[i] = 97;
}
//go back to the char value of the character being encrypted.
input[i] = (char)input[i];
}
return *input;
}
char mediumEncrypt(char input[20])
{
int i, len = strlen(input);
for(i = 0;i < len; i++)
{
input[i] = (int)input[i];
input[i] = input[i] + i;
if(input[i] >= 91)
{
input[i] = input[i]-26;
}
if(input[i] >= 123)
{
input[i] = input[i]-26;
}
input[i] = (char)input[i];
}
return *input;
}
char ultraEncrypt(char input[20])
{
int i, len = strlen(input);
for(i = 0;i < len; i++)
{
input[i] = (int)input[i];
int upper;
if(input[i] >= 65 && input[i] <= 90)
{
upper++;
}
input[i] = input[i] + (i*i);
if(upper == 1)
{
while(input[i] > 90)
{
int count;
count = input[i] - 90;
input[i] = 65 + count;
}
}
else
{
while(input[i] > 122)
{
int count;
count = input[i] - 122;
input[i] = 97 + count;
}
}
input[i] = (char)input[i];
}
return *input;
}
lab2.c
Code:
#include"encrypt.h"//make your function declaration in this .h file
#include<stdio.h>
//#include<encrypt.c>
int main()
{
char input[20], encrypt[7], new[20];
printf("Please enter a sentence to encrypt: ");
scanf("%d", input);
printf("Please enter encryption level: 's' for simple, 'm' for medium, or 'u' for ultra.");
scanf("%d", encrypt);
if(encrypt[0] == 's')
{
printf("Original word is: ");
printf("%d\n", input);
//new = simpleEncrypt(input);
printf("Encrypted word is: ");
printf("%d",simpleEncrypt(input));
}
//1)Request user input and also the security level
//2) Use some datastructure to save the input data
//3) Call the function which is defined in your encrypt.c file
//4) Output the result
return 1;
}