L
L
Lisik2020-11-06 17:45:20
C++ / C#
Lisik, 2020-11-06 17:45:20

A char type argument is not compatible with a const char* type argument. How to fix?

I'm checking for a number. To do this, I create 2 arrays: one char, the other double. After I fill the char array and check if the entered characters are a number. If yes, then I convert them to double. But with the latter, it gives the error described in the title of the question.

double *Array(int size) {
  char* gug = new char[size];
  double* meow = new double[size];
  bool digit = true;
  for (int i = 0; i < size; i++) {
    for (bool check = false; check != true;)
    {
      cin >> gug[i];
      cout << endl;
        if (!isdigit(gug[i]) && gug[0] != '-')
        {
          cout << "You need to enter a digit!" << endl;
          digit = false;
          break;
        }
        else
        {
          digit = true;
        }

      if (digit == true)
      {
        meow[i] = strtod(gug[i], NULL);    //Вот тут ошибка
...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2020-11-06
@Lisik

If you find out that the character is a digit, just subtract '0' from it. if (digit == true) I do not recommend writing, you just need if (digit).
meow[i] = gug[i] - '0';

V
vreitech, 2020-11-06
@fzfx

The strtod function converts strings, and you don't pass a string to it, but a single character, hence the error. First convert gug[i] to a string, and then pass it to the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question