It has been more then a week and I am unable to fix this problem. I double checked everything but I still get this error with capital letters. Can anyone help please?
Here is the code I have for this:
##include <stdio.h>
#include <string.h>
#include <cs50.h>
#include <ctype.h>
int changeTextToASCIInbr(int x);
void getCipherText(int x);
int changeCAPSToASCIInbr(int x);
void getCapsCipherText(int x);
int main(int argc, string argv[])
{
if (argc == 2)
{
int k = atoi(argv[1]);
string p = GetString();
for (int i = 0, n = strlen(p); i < n; i++)
{
if(isdigit(p[i]))
{
printf("%c", p[i]);
}
else
{
if (isupper(p[i]))
{
int capsP = changeCAPSToASCIInbr(p[i]);
int capsCipherText = (capsP + k) % 26;
getCapsCipherText(capsCipherText);
}
else if (isspace(p[i]))
{
printf(" ");
}
else if (ispunct(p[i]))
{
printf("%c", p[i]);
}
else if (islower(p[i]))
{
int ptext = changeTextToASCIInbr(p[i]);
int cipherText = (ptext + k) % 26;
getCipherText(cipherText);
}
}
}
printf("\n");
return 0;
}
else
{
printf("Usage: /home/ubuntu/workspace/week2/pset2/caesar <key>\n");
return 1;
}
}
//changes the char to integer and integer is between 0 and 26. so it changes ascii keys as well.
int changeTextToASCIInbr(int x)
{
int changeIncoming;
changeIncoming = x - 97;
return changeIncoming;
}
//changes the give number (betwen 0 and 26) to its corresponding ascii key and then converts to char.
void getCipherText(int x)
{
int changeIncoming;
changeIncoming = x + 97;
int asc[26];
for (int i = 97; i < 122; i++)
{
asc[i] = i;
}
printf("%c", asc[changeIncoming]);
}
//two bellow functions does the same as above but for capital letters
int changeCAPSToASCIInbr(int x)
{
int changeIncoming;
changeIncoming = x - 65;
return changeIncoming;
}
void getCapsCipherText(int x)
{
int changeIncoming;
changeIncoming = x + 65;
int asc[26];
for (int i = 65; i < 91; i++)
{
asc[i] = i;
}
printf("%c", asc[changeIncoming]);
}
#