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 are near, far and huge pointers?
What is oops c?
What does. int *x[](); means ?
What is the difference between volatile and const volatile?
On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area
What is modifier & how many types of modifiers available in c?
Write a program to identify if a given binary tree is balanced or not.
in linking some of os executables are linking name some of them
Do you know what are bitwise shift operators in c programming?
Explain the difference between null pointer and void pointer.
What is the size of array float a(10)?
Which type of language is c?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
Why is c called c?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm