Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reverse the string content using a function.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
* @desc Algorithm to reverse a string passed by command line as argument.
* Compile: * gcc -o reverse.c -o reverse
* Run: ./reverse SAMARA
* @author Samuel T. C. Santos
void reverse(char str[]){
//Get the text length
int len = strlen(str);
char tmp, i, j;
int middle = len / 2;
//Reverse the string
for(i=0, j=len-1; i < j; i++, j--){
tmp = str[i];
str[i] = str[j];
str[j] = tmp;
int main(int argc, char **argv){
char* text = argv[1];
printf("Reverse: %s \n", text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment