I am trying to reverse a string but when I run the code , the program crashes . What am I doing wrong? The program is supposed to show at first , the string without being reversed and then reversed.
P.S: If you haven't noticed I am totally new in C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void reverseString(char* str);
int main()
{
char* str = "Hello World";
printf(str);
reverseString(str);
return 0;
}
void reverseString(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);
}