Basic beginner loop (with arrays) does NOT work but why?
Hi. I am frustrated with a piece of code I wrote because it malfunctions when the user inputs (command argument style) any string (keyword) with the letter a or A, and I have no idea why and I hate not knowing what's going on. Can you please tell me what I am doing wrong and why the code doesn't work when the user inputs a string with the letter a or A?
Code:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(int argc, string argv[])
{
string keyword = argv[1];
for (int j = 0; j < strlen(keyword); j++)
{
if (keyword[j] >= 'a' && keyword[j] <= 'z')
{
keyword[j] = keyword[j] - 'a';
}
else if (keyword[j] >= 'A' && keyword[j] <= 'Z')
{
keyword[j] = keyword[j] - 'A';
}
printf("%i\n", keyword[j]);
}
}
P.S. The code works fine with every other letter. Just not A or a.
Thank you!