I was refreshing my C knowledge and I happened to cross this program for reversing a string. I have a feeling that the last character of the final reversed string should be assigned '\0' value else it may have a garbage value. Could you please tell if this code is correct or needs to be modified? Thanks in advance!
#include<stdio.h>
#include<string.h>
void main()
{
char str[100],temp;
int i,j=0;
printf("nEnter the string :");
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("nReverse string is :%s",str);
return(0);
}