Post ACMTtdOdCyNapb5ejo by alexbuzzbee@fosstodon.org
 (DIR) More posts by alexbuzzbee@fosstodon.org
 (DIR) Post #ACMTj81P0HzAd2DPeK by abloo@fedi.absturztau.be
       2021-10-14T17:04:41.682057Z
       
       0 likes, 0 repeats
       
       #C questionIn python you can reverse a string with  string = string[::1]Is there anything similar I can do in C?
       
 (DIR) Post #ACMTornuDIic4Gdf2O by chjara@mk.absturztau.be
       2021-10-14T17:05:45.420Z
       
       0 likes, 0 repeats
       
       @abloo@fedi.absturztau.be copy it in reverse order
       
 (DIR) Post #ACMTpyXIfXQzEkOsEa by a1ba@expired.mentality.rip
       2021-10-14T17:05:56.807228Z
       
       0 likes, 0 repeats
       
       @abloo you can't but you can do that inplace, just swap first and last characters.
       
 (DIR) Post #ACMTtP00jiMoBBSnQ0 by NickolasGir@paypig.org
       2021-10-14T17:06:35Z
       
       0 likes, 0 repeats
       
       @abloo You could write a reverse function. Or look one up.
       
 (DIR) Post #ACMTtdOdCyNapb5ejo by alexbuzzbee@fosstodon.org
       2021-10-14T17:06:32Z
       
       0 likes, 0 repeats
       
       @abloo If you're processing the string yourself you can just read backwards (start the pointer at str+len and use -- instead of ++), but I don't think there's a standard way to do it?
       
 (DIR) Post #ACMUXUKUL0I4IJ9jqC by alexbuzzbee@fosstodon.org
       2021-10-14T17:13:43Z
       
       0 likes, 0 repeats
       
       @abloo Some libcs have strrev
       
 (DIR) Post #ACMUYggLtdkUtXxFC4 by TransGal4872@mk.absturztau.be
       2021-10-14T17:14:02.430Z
       
       0 likes, 0 repeats
       
       @abloo@fedi.absturztau.be if you mean get nth index from back, I knowfoo[strlen(foo)]will get you the terminating null, subtract to go backwards, add for segmentation fault.I can give you the C89 answer for doing a full reverse, but it's just doing it long-form in a for(;;) loop
       
 (DIR) Post #ACMUauvLurkFe22AjY by abloo@fedi.absturztau.be
       2021-10-14T17:14:25.734071Z
       
       0 likes, 0 repeats
       
       @alexbuzzbee well, thanks.I almost never touch C and i'm not going to figure out how dmenu works when I could just press "end"Worth a shot
       
 (DIR) Post #ACMUesQL9b6h35PsY4 by TransGal4872@mk.absturztau.be
       2021-10-14T17:15:09.527Z
       
       0 likes, 0 repeats
       
       @abloo@fedi.absturztau.be wait is that hashtag-C or C♯
       
 (DIR) Post #ACMVVLQ8acow2TL9MW by abloo@fedi.absturztau.be
       2021-10-14T17:24:37.949088Z
       
       0 likes, 0 repeats
       
       @TransGal4872 That is hashtag-c
       
 (DIR) Post #ACMXEkh3ZY11PHTBjc by TransGal4872@mk.absturztau.be
       2021-10-14T17:44:03.063Z
       
       0 likes, 0 repeats
       
       @abloo@fedi.absturztau.be to reverse some array foo:(I'm too tired there might be an off-by-one error between n and i, and I might be missing some sequence points)return is manually allocated and must be freed#include <stdlib.h>#include <string.h>char * strreverse (char * foo) {    size_t ell = strlen(foo);    char * bar = calloc(ell + 1,sizeof(char));    size_t i = ell - 1;    for (n;n<ell;n++) {        bar[n] = foo[i];        i--;        assert (i>=0);        }    return bar;    }
       
 (DIR) Post #ACMXHLxxxqClaLcSwa by TransGal4872@mk.absturztau.be
       2021-10-14T17:44:31.018Z
       
       0 likes, 0 repeats
       
       @abloo@fedi.absturztau.be misskey did a good job of syntax-highlighting