Navigation Menu

Skip to content

Commit

Permalink
Adding string reverse
Browse files Browse the repository at this point in the history
Ignore-this: e540c08076a085f909c8c8b6add2e349

darcs-hash:20100422132310-6ac22-9329f45ab1d093b2e96563f7d8d4400bd49c0811.gz
  • Loading branch information
eb committed Apr 22, 2010
1 parent 5bb7fa8 commit 92e7762
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions evm/stdfuns.c
Expand Up @@ -112,6 +112,17 @@ char* strCons(int h, char* str) {
return buf; return buf;
} }


char* strrev(char* str) {
char* buf = EMALLOC((1+strlen(str))*sizeof(char));
int x = strlen(str);
buf[x+1]='\0';
int y = 0;
while(x>0) {
buf[y++] = str[--x];
}
return buf;
}

char* append(char* x, char* y) { char* append(char* x, char* y) {
char* buf = EMALLOC((strlen(x)+strlen(y))*sizeof(char)); char* buf = EMALLOC((strlen(x)+strlen(y))*sizeof(char));
strcpy(buf,x); strcpy(buf,x);
Expand Down
2 changes: 2 additions & 0 deletions evm/stdfuns.h
Expand Up @@ -65,6 +65,8 @@ int strIndex(char* str, int i);
int strHead(char* str); int strHead(char* str);
char* strTail(char* str); char* strTail(char* str);
char* strCons(int h, char* str); char* strCons(int h, char* str);
char* strrev(char* str);

char* append(char* x, char* y); char* append(char* x, char* y);


// Big integer arithmetic // Big integer arithmetic
Expand Down

0 comments on commit 92e7762

Please sign in to comment.