Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

77%
+5 −0
Challenges Reverse an ASCII string

C, 66 59 bytes -7 bytes thanks to Lundin! In-place string reversal f(char*s){s[1]?f(s+1):0;for(char t=*s;s[1];*++s=t)*s=s[1];} Try it online!

posted 4y ago by Moshi‭  ·  edited 4y ago by Moshi‭

Answer
#2: Post edited by user avatar Moshi‭ · 2020-12-02T18:35:57Z (about 4 years ago)
  • ## C, 66 bytes
  • In-place string reversal
  • ```c
  • f(char*s){if(s[1]){f(s+1);while(s[1]){char t=*s;*s=s[1];*++s=t;}}}
  • ```
  • [Try it online!](https://tio.run/##RYuxDoMgGIR3n@JvugCmTR0NpXPfoINxMIBKQtHwYzoQnp2qbdpb7r7LnTwNUuajcdIuSsMVgzLTebzlnsix8wxpND3BpmppXL2sKH@NxupvtW0gCIacodgqzsoSReAppWxcgGdnHKEQC1i1r7Gp65bvPOiABOkH@l@a/fr8o9dh8Q4uvEj5rq2d4DF5qw5v)
  • ## C, <strike>66</strike> 59 bytes
  • *-7 bytes thanks to Lundin!*
  • -----
  • In-place string reversal
  • ```c
  • f(char*s){s[1]?f(s+1):0;for(char t=*s;s[1];*++s=t)*s=s[1];}
  • ```
  • [Try it online!](https://tio.run/##RYu9DoIwFEZ3nuIal/5EAyNWdPUNHAgDKS00Ka3pLRPh2SvWRL/pOzk58jRKmY7GSbsMCq4YB@PP0y1pIqc@MKQrtlV31wR5RS@l0D5kA7FhKD5OMM6xiZRhk3FLxkWYe@MIhbWAfTnAtq47kXlUEQnSL@jfe4W9/GNQcQkOSlFs6aGs9fD0wQ6HNw)
#1: Initial revision by user avatar Moshi‭ · 2020-12-01T23:31:23Z (about 4 years ago)
## C, 66 bytes

In-place string reversal

```c
f(char*s){if(s[1]){f(s+1);while(s[1]){char t=*s;*s=s[1];*++s=t;}}}
```

[Try it online!](https://tio.run/##RYuxDoMgGIR3n@JvugCmTR0NpXPfoINxMIBKQtHwYzoQnp2qbdpb7r7LnTwNUuajcdIuSsMVgzLTebzlnsix8wxpND3BpmppXL2sKH@NxupvtW0gCIacodgqzsoSReAppWxcgGdnHKEQC1i1r7Gp65bvPOiABOkH@l@a/fr8o9dh8Q4uvEj5rq2d4DF5qw5v)