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
What will be the outcome of the following conditional statement if the value of variable s is 10?
When is a “switch” statement preferable over an “if” statement?
What is dynamic memory allocation?
Explain what are compound statements?
All technical questions
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 []);
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
What happens if a header file is included twice?
When should the register modifier be used? Does it really help?
What extern c means?
What is #define used for in c?
c language interview questions & answer
What is advantage of pointer in c?
What is the purpose of main( ) in c language?
What is the time and space complexities of merge sort and when is it preferred over quick sort?