0

I keep getting this error when I try to compile my program: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int'

{
    if (argc != 2)
    {
        printf("Usage: ./caesar key");
        return 1;
    }
  if (argc == 2 )
  {
      printf("Succes\n" "%s\n", argv[1]);
  }

  char *key = atoi(argv[1]);

  int n = strlen(key);

I don t know where is the problem, thank you for helping.

1

The function atoi returns an integer. You're assigning it to a variable of type char *. Change it to int key to fix.

2
  • thank you, but I get the same error – Ema Tabacu May 5 at 10:28
  • @EmaTabacu Are you sure it's not the opposite error? Passing int to parameter of type char*? That's what I would expect from the last line. If you changed key to an int, then you're passing strlen an int, and it takes a char*. Try passing argv[1] to strlen instead. – Fuelled_By_Coffee May 5 at 12:40

You must log in to answer this question.

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