error: invalid operands to binary *

error: invalid operands to binary *

invalid operands to binary expression operator overload
invalid operands to binary expression ('const)
gtest invalid operands to binary expression
this binary operation is invalid for this data type
invalid operands to binary expression color and color
invalid operands to binary
invalid operands to binary % (have 'float' and 'int)
invalid operands to binary expression ('float' and 'float')
#include <stdio.h>
#include <string.h>
#include <math.h>
int main ()
{
  char buf[] ="14:15:43";
  int i;
  char *p;
  int *array[3];
  i = 0;
   p = strtok (buf,":");  
  while (p != NULL)
  {
   array[i++] = p;
    p = strtok (NULL, ":");
  }
  for (i=0;i<3; ++i) {
    //printf("%s\n", array[i]);
    array[i] = array[i] * 2;
 } 
return 0;
}

When I compile the above code I get this error:

split.c: In function ‘main’:
split.c:16:16: warning: assignment from incompatible pointer type
     array[i++] = p;
                ^
split.c:21:25: error: invalid operands to binary * (have ‘int *’ and ‘int’)
     array[i] = array[i] * 2;
                         ^

Regarding the error

In your code, array[i] is of type int *, which cannot be used as the operand of multiply operator.

To quote the standard, chapter §6.5.5 , Multiplicative operators

Each of the operands shall have arithmetic type.

~~~~see note~~~~~

Regarding the warning

That said,

 array[i++] = p;

looks very wrong. array[n] is of type int *, and p is of type char * and they are not compatible types. You may want to check your logic all over again.

Solution

It looks like, you want to perform arithmetic operation on the numeric value of the string content. FYI, just casting the char * to int * does not make the content of the string to appear as int.

For that, you need to convert the string to arithmatic type first, say int or long. strtol() may be of your help.


[NOTE]

arithmetic type:

Quoting C11, chapter §6.2.5,

Integer and floating types are collectively called arithmetic types.

Invalid Operands to binary Expression, C, *avg = (*total / lines);. In fact, you probably want to use floating point division on the second error there (some compilers are notorious for using  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. What does error: invalid operands to binary % (have


A few errors here:

You're defining your array as int *array[3] i.e. an array of int *, however what you probably want is int array[3], i.e. an array of int.

Next, as was mentioned elsewhere, array[i++] = p is invalid because you're trying to assign a char * to an int * (or an int if you first apply the first fix), which is invalid. You want to convert the string to an integer using atoi as array[i++] = atoi(p).

Lastly, your commented out printf in the for loop should be using %d for the format specifier instead of %s, since the array contains int. You probably also want to move it down one line, right after array[i] = array[i] * 2.

With the above changes, you now have this:

#include <stdio.h>
#include <string.h>
#include <math.h>
int main ()
{
  char buf[] ="14:15:43";
  int i;
  char *p;
  int array[3];
  i = 0;
   p = strtok (buf,":");
  while (p != NULL)
  {
   array[i++] = atoi(p);
    p = strtok (NULL, ":");
  }
  for (i=0;i<3; ++i) {
    array[i] = array[i] * 2;
    printf("%d\n", array[i]);
 }
return 0;
}

Which outputs this:

28
30
86

Error: Invalid operands to binary / - MATLAB Answers, Error: Invalid operands to binary / (have 'real_T {aka const double}' and 'const real_T * {aka const double *}'). dx[3] = xC[11]*xC[4]  Error: invalid operands to binary & (have ‘char *’ and ‘int’) Hello friends, I am learning C programming under linux recently, this is a example I tried, but


It can also mean something completely different. Think about the meaning of "invalid operand". I was getting it on

fftout[lochead][i][0] * fftout[lochead][i][0]

When I forgot the [i] terms. I have 10 buffers, each with 4096 elements, each of those with 2 elements. I didn't have enough indexes.

And yes, I'm just squaring the number. It's part of a square root of sums of squares demodulation step.

invalid operands to binary, error: invalid operands to binary *. How the heck am I getting this error? error: invalid operands to binary *. Code: [View]. *(yuv->y + i) = (0.257)  > hours_3b.c:151: error: invalid operands to binary + (have ‘float *’ and ‘float’) > hours_3b.c:153: error: invalid operands to binary + (have ‘float *’ and ‘double’) Something in each one of them is a pointer. Did you forget a subscript.


C Board, Error: invalid operand to binary % of two numbers being divided is zero and I get the error "invalid operands to binary" on this line of code:. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more error: invalid operands to binary ^ (have ‘float’ and ‘float’) [duplicate]


error: invalid operands to binary << · Issue #8263 · openzfs/zfs · GitHub, Linux 5.0: error: invalid operands to binary << #8263. Closed. tonyhutter opened this issue on Jan 10, 2019 · 0 comments. Closed  Simple - don't compare the value the function doesn't return to a constant.


Invalid operands to binary % - C / C++, Invalid operands to binary - · [?] invalid operands to binary & · error: invalid operands to binary & · Browse more C / C++ Questions on Bytes  5ed; good catch. Plus, I made the change as to what Carlo has said above and the program is also C++ so I changed the function call, resource links.