I want to take a substring of the string buffer by doing something like the below. I don’t know if it’s possible (I’ve been coding in C for all of about 6 hrs now, but feel free to be as technical as you like, I think I can handle it (though I may be wrong))
Edit: I want to take a substring of buffer from the beginning of buffer to the first space.
if (buffer[c] == ' ') {
in_addr_t addr;
char *ptr = *buffer;
if(inet_aton("*ptr to *ptr+c", &addr)!=0){
//do stuff;
}
}
I have to make one assumption since there are a number of problems with the code: Assuming that buffer[c] is the first character before the inet address
Note:
inet_atonis deprecated since it does not support ipv6. Useint inet_pton(int af, const char *src, void *dst);for forward compatibility.— Edit —
To take the substring from the beginning of
bufferto (but not including)buffer[c], any of these will work:1
2
3