Hi all,
I prepared a program in c language to reverse a string using recursive function
In my program I terminated the string using new line character '\n'
But I want to change my program in the way that if a white space is pressed after typing a word then space bar ' ' should be used to terminate the string and string should be printed in reverse order
but when I used statement
then string is not being terminated after executing the program
here is the coding I used to apply my logic
please guide me about the solution to this problem
Thank you
I prepared a program in c language to reverse a string using recursive function
In my program I terminated the string using new line character '\n'
But I want to change my program in the way that if a white space is pressed after typing a word then space bar ' ' should be used to terminate the string and string should be printed in reverse order
but when I used statement
Code:
if((ch=getchar())!=' ') rev();
here is the coding I used to apply my logic
Code:
void rev(void) { char ch; if((ch=getchar())!='\n') { rev(); printf("%c",ch); } }
Thank you
Comment