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 will be the outcome of the following conditional statement if the value of variable s is 10?

755


When is a “switch” statement preferable over an “if” statement?

643


What is dynamic memory allocation?

804


Explain what are compound statements?

601


All technical questions

1506






write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);

1840


C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions

606


What happens if a header file is included twice?

585


When should the register modifier be used? Does it really help?

607


What extern c means?

529


What is #define used for in c?

609


c language interview questions & answer

1455


What is advantage of pointer in c?

687


What is the purpose of main( ) in c language?

615


What is the time and space complexities of merge sort and when is it preferred over quick sort?

673