{}
run-icon
main.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> // char*c(char*s,char*i){char*r=malloc(strlen(s)),*z,o,t;r=strcpy(r,s);for(;*i;++i){z=strchr(r,'|');o=(*i==60&&z-r)?-1:(*i==62&&z[1])?1:0;t=*z;*z=z[o];z[o]=t;if(*i==35&&z-r)memmove(z-1,z,strlen(z)+1);}return r;} char *c(char *s, char *i) { char *r = malloc(strlen(s)), *z, o, t; r = strcpy(r, s); for (; *i; ++i) { z = strchr(r, '|'); o = (*i == 60 && z - r) ? -1 : (*i == 62 && z[1]) ? 1 : 0; t = *z; *z = z[o]; z[o] = t; if (*i == 35 && z - r) memmove(z-1, z, strlen(z)+1); } return r; } int main(void) { char *res = c("This is a test|", "#<<<<<######>"); assert(strcmp(res, "Tha| tes") == 0); free(res); res = c("Curs|or end test", ">>>>>>>>>>>>><>"); assert(strcmp(res, "Cursor end test|") == 0); free(res); res = c("Cursor s|tart test", "<<<<<<<<<<<><"); assert(strcmp(res, "|Cursor start test") == 0); free(res); res = c("Delete all|", "##############><<<"); assert(strcmp(res, "|") == 0); free(res); res = c("|", ">><##>"); assert(strcmp(res, "|") == 0); free(res); return EXIT_SUCCESS; }
Output