Instead of using a while loop to iterate through a linked list, consider using a for loop. Node * iter; for (iter=root; iter != NULL; iter=iter->next) { /* iter->object; */ } A concise implementation of strlen size_t strlen(char * str) { char * cur; for(cur=str; *cur; ++cur); return (cur-str); } Reverse a string in-place. void reverse(char * str) { char *i,*j, tmp; for (i=str, j=(str+strlen(str)-1); i
Anyhow, when asked to write those on a blackboard, I typically do this:
size_t strlen(char* start) {
char* end=start;
while(*end) ++end;
return (end-start);
}
and void reverse(char* i) {
char* j=(i+strlen(i)-1);
for (; i