-3

I am trying to check the key of the cipher text to see if every character is an integer. The code When I compile the program I get the following error code compiling error

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 2
    Please post code and errors as text, not images. Please read about creating [Minimal, Reproducible Examples](https://stackoverflow.com/help/minimal-reproducible-example), and consider reading [*How do I ask a good question?*](https://stackoverflow.com/help/how-to-ask) as well. – Oka Jun 05 '23 at 03:12
  • thanks for that, I will look into to improve. – Rochdi Hadfi Jun 05 '23 at 03:53
  • You can [edit] your question right now. – n. m. could be an AI Jun 05 '23 at 05:42
  • There are lots of questions with the tags [cs50] and [caesar-cipher]. Most of them will show you what you need to know. – Jonathan Leffler Jun 05 '23 at 11:05

1 Answers1

-1

You can do as bellow:

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

bool only_digits(string key);
void print_usage() {
  printf("Usage: ./caesar key\n");
}

int main(int argc, string argv[]) {
  if (argc != 2) {
    print_usage();
    return 1;
  }

  if (!only_digits(argv[1])) {
    print_usage();
    return 1;
  }
  return 0;
}

bool only_digits(string key) {
  int key_length = strlen(key);
  for (int i = 0; i < key_length; i++) {
    if (isdigit(key[i]) == 0) {
      return false;
    }
  }

  return true;
}

Your problem is:

  1. Line 6: only_digits should receive argument type string, not string[1] (array of string)
  2. Line 26, 33: argv[1] is the way you access to the 2nd element in argv array. While argv[1] in function prototype bool only_digits(string argv[1]) is declaring an argument with array type (with 1 element)
binhgreat
  • 982
  • 8
  • 13