0
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;

int main()
{
    int i,len,t;
    cin>>t;
    char a[100],b[100];
    while(t>0)
    {
                                                
              cin>>a;
              len=strlen(a);len=len-1;
              for(i=0;i<=len;i++)
              {
                                 b[i]=a[len-i];
              }
              cout<<"value of a\n"<<a<<"\n"<<b;
              if(strcmp(a,b)==0)
              cout<<"YES"<<endl;
              else
              cout<<"NO"<<endl;
             
              t--;
    }
    getch();
    return 0;
}

every time the loop runs the garbage value of char b; remains. . .how to clear the old values of b?

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Comatose
1

Or perhaps fix b so that it's a proper \0 terminated string, then the problem goes away.

Votes + Comments
Damn. Good Eye.
0

the '\0' did work but is nt there any command like string.clear(). .
cout<<flush; did not work too. . .

0

Not with a character array (that I know of). In order to get all the wonderful toys, you need to use std::string.
I suppose you could set indice 0 to '\0'....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.