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 is the concatenation operator?
How can I find out if there are characters available for reading?
What is memory leak in c?
Explain how can I open a file so that other programs can update it at the same time?
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
hi, which software companys will take,if d candidate's % is jst 55%?
What is C language ?
how to find anagram without using string functions using only loops in c programming
Difference between MAC vs. IP Addressing
Where register variables are stored in c?
Explain the difference between getch() and getche() in c?
What is function in c with example?
What is the difference between ++a and a++?
How many data structures are there in c?
What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?