Reverse a string in C language

how to reverse a string in C language ?
this is the code

#include<stdio.h>

int main()
{
    int a,A;
    char array[101],temp;
    scanf("%s",&array);
    a=0;
    while(a>=0)
    {
        if(array[a]=='\0')break;
        a++;
    }
    for(A=0;A<=a/2;A++)
    {
        temp=array[A];
        array[A]=array[a-A-1];
        array[a-A-1]=temp;
    }
    for(A=0;A<a;A++)
    {
       printf("%c",array[A]);
    }
    return 0;
}

or you can simply using function in strrev in string.h

#include<stdio.h>
#include<string.h>
  
int main()
{
   char array[101];
scanf("%s",&array);
   printf("After reversing string is =%s",strrev(str));
   return 0;
}
strrev is not recommended for use in competitive coding

that is all from me
thank you

Comments