Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone look at my code and tell me whats wrong i use visual studio amd its

ID: 3675029 • Letter: C

Question

Can someone look at my code and tell me whats wrong i use visual studio amd its not doing what is supposed to

#include<stdio.h>

int main(){

   char str[100];

   int i = 0, j = -1, flag = 0;

   printf("Enter a string: ");

   gets_s(str);

   while (str[++j] != ''){

       j--;
   }
   while (i < j){

       if (str[i++] != str[j--]){

           flag = 1;

           break;

       }
   }


   if (flag == 0)

       printf("The string is a palindrome");

   else

       printf("The string is not a palindrome");

   return 0;

}

Explanation / Answer

#include<stdio.h>

int main(){

  char str[100];

  int i=0,j=-1,flag=0;

printf("Enter a string: ");

scanf("%s",str);

  while(str[++j]!='');

j--;

  while(i<j)

      if(str[i++] != str[j--]){

         flag=1;

           break;

    }

   

  if(flag == 0)

      printf("The string is a palindrome");

  else

      printf("The string is not a palindrome");

  return 0;

}

Output:

Enter the string Wow

the string is a palindrome