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

int main(int argc, string argv[])
{
  //getting correct input for KEY
  if (argc == 2 && isdigit(argv[1]))
  {
      int k = atoi(argv[1]);
      string s = get_string("Plain Text:\n");
      printf("CIPHER TEXT:");
      
      for (int i = 0, n = strlen(s); i < n; i++)
      {
          if ( islower(s[i]) )
          printf("%c" , ((s[i]) + k) % 26);
          
          else if (isupper(s[i]))
          printf("%c", ((s[i]) + k) % 26);
          
          else
          printf("%c", s[i]);
      }

  }
  else
  printf("enter valid Key\n");
  return 1;

}
0
             isdigit(argv[1])

The isdigit() function takes a single char as input, but argv[1] is a string. Feeding a string to isdigit causes the seg fault.

There are more bugs waiting for you, but you deserve the chance to fix them first.

You must log in to answer this question.

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