I am writing code for caesar but when i am executing the program i am not getting any output and when i try to print integer values instead characters it is giving weird integer values, with this i can conclude that i am getting values more than 127 but don't understand how that is happening in my code. can anyone please pint out the mistake.
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
char begin_index(char c );
char original_index(char c);
int main(int argc,string argv[])
{
if (argc==2)
{
//printf("Success\n");
//printf("Key : %s\n",argv[1]);
for(int i = 0,n = strlen(argv[1]);i<n;i++)
{
if(isdigit(argv[1][i])==0)
{
printf("Usage: ./caesar key\n");
//break;
return 1;
}
}
int key = atoi(argv[1]);
printf("Key: %i\n",key);
string plain_text = get_string("plain_text:");
for (int i = 0,n = strlen(plain_text);i<n;i++)
{
if(isalpha(plain_text[i]))
{
plain_text[i] = begin_index(plain_text[i]);
char ci = (plain_text[i] + key) % 26;
ci = original_index(ci);
printf("%c",ci);
}
else
{
printf("%c",plain_text[i]);
}
}
printf("\n");
}
else
{
printf("Usage: ./caesar key\n");
}
}
char begin_index(char c )
{
if(islower(c))
{
c = c - 97;
}
else if (isupper(c))
{
c = c - 65;
}
return c;
}
char original_index(char c)
{
if(islower(c))
{
c = c + 97;
}
else if (isupper(c))
{
c = c + 65;
}
return c;
}