Reverse in place in C
Reverses in place with two indices walking toward each other.
void reverse(char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len / 2; i++) {
char tmp = s[i];
s[i] = s[len - 1 - i];
s[len - 1 - i] = tmp;
}
}
Keywords and builtins used here
charforreversesize_tvoid
The run, in numbers
- Lines
- 8
- Characters to type
- 152
- Tokens
- 69
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 41 seconds.
Step 1 of 2 in Strings in memory, step 22 of 25 in Pointers & memory.