Created
February 22, 2017 06:13
-
-
Save scroobius-pip/457e81ea4f49d4a7b3eb71cf5543b751 to your computer and use it in GitHub Desktop.
String reversal function in c
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 <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