Last active
August 29, 2015 14:03
-
-
Save benaryorg/d2011aecdc56a30bbe86 to your computer and use it in GitHub Desktop.
C data reversal function (recursive)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _datarev(char *base,char *data,const unsigned int len) | |
{ | |
if(data-len<=base) | |
{ | |
char ch=*data; | |
_datarev(base,data+1,len); | |
base[(base-data)+len]=ch; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern void _datarev(char *,char *,const unsigned int); | |
#define datarev(data,len) _datarev((data),(data),((len)>0)?(len):0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include "datarev.h" | |
int main(void) | |
{ | |
char arr[27]={}; | |
int i; | |
for(i=0;i<26;i++) | |
{ | |
arr[i]=i+'a'; | |
} | |
datarev(arr,strlen(arr)-1); | |
puts(arr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment