Where is it not working? If ithere are compile errors, give us the error messages. At first glance getche(); should be changed to getchar();
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Many problems in your code to begin with:Dont use conio.h its a non standard header file ( you seem to be using Turbo C )
Dont use clrscr() to clear the screen. Its a non portable function which works only on Turbo C. Use it at your own risk
What you are trying to do is called "finding whether a string is Palindrome" i.e. if a word both in its original form and reversed is the same. eg. deed, civic
Are you sure you want to accpet the input character by character ? Because normally input is accpeted in form of strings.
If you want in string form then consider something like:
#include <stdio.h>
#include <string.h>
void remove_newline( char* input )
{
char* p = 0 ;
if( p = strrchr( input, '\n' ) )
*p = '\0' ;
}
int main( void )
{
int i = 0 , j = 0;
char buffer[BUFSIZ] = {'\0'} ;
printf( "Enter the string: " ) ;
fgets( buffer, BUFSIZ, stdin ) ;
remove_newline( buffer ) ;
int length = strlen( buffer ) ;
char* my_string = (char*) malloc( length + 1 ) ;
for( i = 0, j = length - 1; j >= 0; --j, ++i)
{
my_string[i] = buffer[j] ;
}
my_string[i] = '\0' ;
printf( "The new string: %s", my_string ) ;
}
Though its a lengthy way, but is simple to understand for a beginner.
Make the required changes if you want to accept the user input in form of single characters. If any problems then repost your doubts.
Hope it helped, bye.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
my if condition is not working properly
That is because your logic is wrong.
for(j=0;j<a;j++)
{
q--;
namre[q]=name[j];
}
if( strncmp(namre,name,num ) == 0)
{
printf("the word is same");
}
else
{
printf("the word is not same");
}
Use #include <string.h> at the beginning of your code.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115