#include <stdio.h> #include <stdlib.h> int len(const char*str) { int result=0; GETATIT: if (*(str+result++)=='\0') goto END; goto GETATIT; END: return result; } char*reversed(const char* str) { #define reset i=0 char*result=(char*)malloc(sizeof(char)*len(str)); int reset; YOUCANDOIT: if ((*(result+len(str)-1-i)=*(str+i))=='\0') goto ONEMORESTEP; ++i; goto YOUCANDOIT; ONEMORESTEP: reset; LOOP: *(result+i)=*(result+i+1); if (i++>=len(result)-1) goto WEDIDIT; goto LOOP; WEDIDIT: *(result+i)='\0'; return result; } int main(int argc, char*argv[]) { const char*str="Foo!"; char*reverse=reversed(str); printf("%s\n",reverse); free(reverse); return 0; }
WEDIDIT 🎉
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
WEDIDIT 🎉