You dint check the return value of calloc and dont really see the point of thisCode:char *y=calloc(1,strlen(s)+1); char *p=s+strlen(s);
ssharishCode:if( !strchr(delims,*s) ) strcat(y,s);
You dint check the return value of calloc and dont really see the point of thisCode:char *y=calloc(1,strlen(s)+1); char *p=s+strlen(s);
ssharishCode:if( !strchr(delims,*s) ) strcat(y,s);
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
What's the difference between calloc and malloc?
Can you explain this loop a bit for me?
It's mainly the strcat line that I'm lost on because all of that is on one line with a comma separating them. Thanks.Code:while( p!=s ) if( strchr(delims,*--p) ) strcat(y,p+1),strncat(y,p,1),*p=0;
That is just a (misguided) attempt to make the code more concise. It could have been written as:Originally Posted by mherald81
Code:char *wordrev(char *s, const char *delims) { char *y = calloc(1, strlen(s) + 1); char *p = s + strlen(s); while (p != s) { if (strchr(delims, *--p)) { strcat(y, p + 1); strncat(y, p, 1); *p = 0; } } if (!strchr(delims, *s)) { strcat(y, s); } strcpy(s, y); free(y); return s; }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Last edited by mherald81; 10-17-2010 at 09:24 AM.