I want to write a function void reverse_string(char* s) that reverses in place the contents of the null-terminated C string given to it as parameter.
So I got it to reverse the content with no parameter. But I want to know how to implement the parameter into this like from the command line.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void reverseString(char* str);
int main()
{
char str [256];
strcpy_s(str, "Hello World");
printf(str);
reverseString(str);
return 0;
}
void reverse_String(char* str)
{
int i, j;
char temp;
i=j=temp=0;
j=strlen(str)-1;
for (i=0; i<j; i++, j--)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
printf(str);
}
Any help is appreciated.