I have a text containing a list of ip:port and I have a multi-threading program that splits them to IP and port separately I used strtok but it gives a lot of errors and problems and makes the program gets segmentation fault every time + it needs make to strdup char pointer which very annoying I used strchr but it only gives me the port but can't use it to extract the IP the goal is extract IP as a string and the port as integer and never gets segmentation failed whatever
example:
This is the start function of the thread
void* startthread() {
do {
char* proxy = "127.0.0.1:443";
char* buffered = strdup(proxy);
char* host = strtok(buffered,":");
int port = atoi(strtok(NULL,":"));
printf("%s:%d",host,port);
}while(1);
}
gdb
Thread 8 "main" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff4a34700 (LWP 47410)]
__GI_____strtol_l_internal (nptr=0x0, endptr=endptr@entry=0x0,