info@thistimebd.com

Wednesday 24th of April 09:02:56am

Write a for loop that will read the character in a character type array called text and write the character backwards into another character type array called back text. Assume that text contains 80 characters. Use the comma operator within for loop

Write a for loop that will read the character in a character type array called text

and write the character backwards into another character type array called back

text. Assume that text contains 80 characters. Use the comma operator within for

loop.


Solution:


#include<stdio.h>

#include<conio.h>

int main()

{

char text[80];

char backtext[80],ch;

int i,j,len=0;

printf("Note: Please end with full stop ");

printf("Enter a string and please End with a . (fullstop) : ");

for(i=0; i<80; ++i)

{

ch=getche();

if(ch== .) // use single quatation

break;

text[i]=ch;

len++;

}

j=len;

for(i=0; i<len; ++i)


{

backtext[i]=text[j-1];

j--;

}

printf(" Revarse text is : ");

for(i=0; i<len; ++i)

printf("%c",backtext[i]);

getch;

}