0

enter image description hereI'm having trouble running my code because of a permission denial...Could someone please help me? THanks :)

Here's my code:

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

int main(int argc, string argv[])
{
    if (argc == 2 && isdigit(*argv[2]))
    {
        printf("Usage: ./caesar key\n");
        return 1;
        
    }
    int cle = atoi(argv[1]);
    
    string m = get_string("Please enter plaintext here: ");
    
    printf("Here is the ciphertext translation: ");
   
    for (int i = 0, p = strlen(m) ; i < p; i++)
    {
         if (m[i] <= 'Z' && m[1] >= 'A')
        {
            
        printf("%c", (((m[1] - 'A') + cle) % 26) + 'A');
        }
        
        else if (m[1] <= 'z' && m[1] >= 'a')
        
        { 
          printf("%c", (((m[1] - 'a') + cle) % 26) + 'a');
    }
    
    else 
    
    {
        
    printf("%c", m[1]);
    
    }
    
printf("\n");
 return 0;
    }
    
 
    
    {
        printf ("Usage: ./caesar k\n");
        return 1;
    }


}
2
  • It's more important that you describe the "permission denied" issue. Can you give more details? Post a screenshot of the IDE showing how you tried to execute the program and the resulting error?
    – Cliff B
    Dec 2 '20 at 22:14
  • perfect i just posted it thanks Dec 2 '20 at 22:24
0

A segmentation fault is not a permission error. It's a memory access error. The code is trying to access memory it shouldn't.

Specifically, the error lies here: isdigit(*argv[2])

The isdigit() function takes a single character as input. argv[2] is a string (or char array). When you give a string as a parameter to isdigit or any of it's cousin functions, it will generate a seg fault.

The code needs to check each char in the argv[2] string. I suggest you try a for loop.

Tip: Check out the following: Do YOU know how to find a seg fault?? Advice to new programmers

0

You're trying to run the uncompiled .c code instead of the binary.

Try running:

./caesar
3
  • even when I run ./caesar, it doesnt work I dont know why :( Dec 2 '20 at 22:38
  • I posted a more recent shot Dec 2 '20 at 22:46
  • In fairness, it was the problem in the first instance. If you check the edit history you'll see that in the first instance the OP was trying to execute caesar.c and receiving the expected permission denied error from bash.
    – Sentox
    Dec 2 '20 at 23:26

You must log in to answer this question.

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