0

Hi I tried running the following code -- although it is compiling it is not returning anything.

#include<cs50.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>

int main(int argc, string argv[])
{
    while(argc != 2)
    {
        printf("Please provide 2 arguments.\n");
        return 1;
    }
    string a = GetString();
    int p = atoi(argv[1]);
    for(int i = 0; i < strlen(a); i++)
    {
        char m[i];
        if(('A' <= a[i] && a[i] <= 'Z') || ('a' <= a[i] && a[i] <= 'z'))
        {
            m[i] = (a[i] + p) % 26;
        }
        else
        {
            m[i] = a[i];
        }
    printf("%c", m[i]);
    }
return 0;
}

1 Answer 1

0

Problem lies within the if condition. decimal value of m[i] as per ascii will never exceeds 25 whereas the alphabets are starting from 65 and 97.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .