string - C syntax, please explain this code snip? -
string - C syntax, please explain this code snip? -
can explain code below? how reversing order of chars in string?
void reverse_string(char *str) { /* skip null */ if (str == 0) { return; } /* skip empty string */ if (*str == 0) { return; } /* range */ char *start = str; char *end = start + strlen(str) - 1; /* -1 \0 */ char temp; /* reverse */ while (end > start) { /* swap */ temp = *start; *start = *end; *end = temp; /* move */ ++start; --end; }
it swaps first character , lastly character. swaps sec character next last. , on until it's done.
c string
Comments
Post a Comment