I have been working through the caesar code and all is well until I start playing about with the isupper function. This is where the problem is as I've been compiling and running the rest of the program no problem:
int k = atoi(argv[1]);
string p = GetString();
for (int j = 0, n = strlen(p); j < n; j++)
{
if (isupper('p[j]'))
{
int upper = ('p[j]' - 65);
upper = ((upper + k)%26);
upper = (upper + 65);
printf("%c", upper);
}
}
When I run the program it awaits the string from the user, I input any letter and get back Segmentation fault (core dumped). I know that this is to do with touching areas of memory I'm not supposed to, one of the likely solutions was that I was trying to call toupper on a string instead of a char, but p[j] should definitely be a character in the plaintext. To test this I replaced both instances of 'p[j]' with 'A', and it compiles and runs no problem. What is the problem with calling toupper on 'p[j]'? If p is the plaintext string, shouldn't 'p[j]', with quotes, be a character in the string?? Any help appreciated, thanks!