#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?

Recommended Answers

All 4 Replies

memset (b, '0', 100); ?

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

commented: Damn. Good Eye. +10

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

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'....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.