I need to take an argument (argv[2]) and convert it to uint16_t type. How I can get this? I put a PORT in argument so I need to convert in uint16_t, I tried this:
uint16_t PORT;
PORT = argv[2];
but when I do
servaddr.sin_port = htons(PORT)
I get
warning: assignment makes integer from pointer without a cast
You can convert a char *
to an int
(and therefore, to a uint16_t
) via the atoi()
function:
#include <stdlib.h>
[...]
uint16_t PORT = atoi(argv[2]);