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 purpose of sprintf() function?
How do I use void main?
What is union and structure?
What is operator precedence?
What is function prototype in c with example?
What is the difference between malloc() and calloc()?
Write a code to generate divisors of an integer?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
How many bytes are occupied by near, far and huge pointers (dos)?
What are the functions to open and close the file in c language?
What are the types of i/o functions?
Explain Basic concepts of C language?
Write a program to swap two numbers without using the third variable?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What is new line escape sequence?