I am developing a program to read 2 strings (addresses) entered by the user and then apply the operator &
and thus obtain a new address.
For example, if the user enters 172.217.0.164
and then 255.255.0.0
, the result of applying the operator &
between the two addresses would be 172.217.0.0
. Which is what I intend to obtain when performing the operation in C
.
The problem is that I get the following error:
[Error] invalid operands to binary & (have 'char *' and 'char *')
- The code in
C
:
#include <stdio.h>
#include <stdlib.h>
int main(){
char *direccion;
char *mascara;
direccion = (char *)calloc(16, sizeof(char));
mascara = (char *)calloc(16, sizeof(char));
printf("Introduce la primera direccion ip: ");
scanf("%s", direccion);
printf("Introduce la mascara de dicha direccion: ");
scanf("%s", mascara);
/*aplicar bit a bit con el operador &*/
char *n;
n = direccion & mascara;
printf("La nueva direccion es la siguiente %s", n);
return 0;
}