MK27 very kindly answered the OP's question (a good one, IMO, since I'm trying to solve the same problem):
"IMO you do not actually make much sense. I would also guess that
Quote: I'm comfortable with the code behind what I've described
does not refer your (obviously non-existent) knowledge of the C programming language. Please be honest, life is much easier that way."
So naturally, always wanting to learn new stuff from one who has knowledge of the C programming language (KCPL), I took a look at the code that MK27 generously gave us:
Code:
void pretrunc (char *string, int chs) {
int i;
for (i=0;i<strlen(string);i++) string[i]=string[i+chs];
string[i]='\0';
}
struct in_addr parseaddr (char *addr) {
struct hostent *info;
struct in_addr address, *ptr;
if ((strncmp(addr,"http",4))==0) pretrunc(addr,7);
...
}
Excellent! D'ya suppose there's some way to get rid of pretrunc()? It's called only once in grabimage.c so maybe it doesn't have to be a function at all. Let's give it a shot:
Code:
struct in_addr parseaddr (char *addr) {
int i;
struct hostent *info;
struct in_addr address, *ptr;
if ((strncmp(addr,"http",4))==0) {
for (i=0;i<strlen(string);i++) string[i]=string[i+chs];
string[i]='\0';
}
...
}
Great! We got rid of an unneeded function and the whole thing is easier to read and follow. But wait a sec: isn't there a better way to delete the constant string "http://" than to move all the chars in the URI one-by-one? Let's see:
Code:
struct in_addr parseaddr (char *addr) {
int i;
struct hostent *info;
struct in_addr address, *ptr;
if ((strncmp(addr,"http",4))==0) {
memmove(addr, &addr[7], strlen(addr) + 1);
}
...
}
Hey, that looks OK! memmove() copies a bunch of chars from place to place in one shot, and without that loop and the pesky call to strlen() every time through. Thanks, MK27, for a great lesson from one who has KCPL.
I haven't done too much with the togbool() function that is in mine.h:
Code:
int togbool (int *boo) {
if (*boo==0) *boo=1;
else *boo=0;
return *boo;
}
I guess this a function that toggles a boolean between TRUE and FALSE. Does this really have to be a function? We're talking about doing an XOR on one bit:
Would that work? Or something like that?
Don'cha love to learn new stuff? Thanks a million MK27!
-- pt