Write a function that accepts a sentence as a parameter, and
returns the same with each of its words reversed. The
returned sentence should have 1 blank space between each
pair of words.
Demonstrate the usage of this function from a main program.
Example:
Parameter: “jack and jill went up a hill” Return Value:
“kcaj dna llij tnew pu a llih”

Answer Posted / ayas kumar das

#include"stdio.h"
#include"string.h"
main()

{

char a[200],b[20][20];

char c[200],d[20][20];

int i,j=0,k=0,y=0,l;

memset(b,0,sizeof(b)); //initializing the array



printf("enter your own string:");
//Enter the string which you want
gets(a);


for(i=0;i<strlen(a);i++)

{

if(a[i]!=' ')

{

b[j][k]=a[i];

k++;

y++;

}

else

{
if(y!=0)
//if there are more than one space
between two words
{

while(a[i]==' ')

{

i++;

}

i--;

k=0;

j++;

}

else


//if initialy there are more than one space
{

while(a[i]==' ')

{

i++;

}

i--;

y++;


}

}

}

for(i=0;strlen(b[i]);i++)

{

k=strlen(b[i]);

for(l=k;l>=0;l--)

{

printf("%c",b[i][l]); //here reversing
each word

}

printf(" ");

}

return 0;

}
//enter "jack and jill went up a hill"

Is This Answer Correct ?    13 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are preprocessor directives in c?

749


Why structure is used in c?

690


What are the preprocessor categories?

715


What is conio h in c?

716


#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }

772






How old is c programming language?

679


What is difference between main and void main?

711


What is the full form of getch?

731


Explain what are linked list?

716


What is atoi and atof in c?

709


void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply

2355


Define Spanning-Tree Protocol (STP)

752


What is a program flowchart?

698


Why do we need a structure?

680


Why we not create function inside function.

1853