Hello and thanks for reading.
I have created a few functions and at the moment I have no idea if my code works, so I just want to test to see if my code works but I am getting a weird error which I've spent ages trying to fix.
error: unused variable 'key' [-Werror,-Wunused-variable]
I have used the key variable in the functions below, but I am getting this error. I feel as if it has something to do with the key variable not being global? Any help is appreciated.
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h> // for atoi(), string to int
#include <ctype.h>
int upperConv(int input);
int lowerConv(int input);
int key;
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Please enter an integer for the key after ./caesar");
return 1;
}
int key = atoi(argv[1]);
string input = GetString();
for(int i = 0, n = strlen(input); i < n; i++)
{
if (isupper(input[i]))
{
printf("%c", upperConv(input[i]));
}
else if (islower(input[i]))
{
printf("%c", lowerConv(input[i]));
}
}
}
int upperConv(int input)
{
int x = input - 65 + key;
int z = x % 26;
z = z + 65;
return z;
}
int lowerConv(int input)
{
int x = input - 97 + key;
int z = x % 26;
z = z + 97;
return z;
}