Skip to content

Instantly share code, notes, and snippets.

@scroobius-pip
Created February 22, 2017 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scroobius-pip/457e81ea4f49d4a7b3eb71cf5543b751 to your computer and use it in GitHub Desktop.
Save scroobius-pip/457e81ea4f49d4a7b3eb71cf5543b751 to your computer and use it in GitHub Desktop.
String reversal function in c
#include <stdio.h>
#include <string.h>
#include <math.h>
char* reverse(char*);
int main(void) {
char s[] = "abcdefghijklmnopqrstuvwxyz";
printf("%s",reverse(s));
return 0;
}
char* reverse(char* string){
int length = strlen(string);
int limit = (int)floor(length/2);
printf("%d \n",limit);
char temp;
for(int x = 0;x<limit;x++){
temp = string[x];
string[x] = string[length-x-1];
string[length-x-1] = temp;
}
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment