EDITED: I have managed to edit the mistakes but I don't understand why it is not returning 1 when argv[1] is not keyed in.
Can someone tell me if I am doing anything wrong with:
if (argc == 2)
{.....
}
else return 1;
Here is my code:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
if (argc == 2)
{
int k = atoi (argv[1]);
string p = GetString();
for (int i = 0, n = strlen(p); i<n; i++)
{
if (isalpha(p[i]))
{
if (islower(p[i]))
{
int l = p[i];
int lresult = (k + l);
if (lresult>122)
{
int modlresult = (((p[i] - 97) + k) % 26) + 97;
printf ("%c", modlresult);
}
else
printf("%c", lresult);
}
else if (isupper(p[i]))
{
int u = p[i];
int uresult = (k + u);
if (uresult>90)
{
int moduresult = (((p[i] - 65) + k) % 26) + 65;
printf ("%c", moduresult);
}
else
printf("%c", uresult);
}
}
else
printf ("%c", p[i]);
}
printf ("\n");
return 0;
}
else
return 1;
}