1. Write a program to reverse every second word in a
given sentence.



1. Write a program to reverse every second word in a given sentence. ..

Answer / lalit

#include <stdio.h>
#include <string.h>

void main()
{
int i, j = 0, k = 0, x, len;
char str[100], str1[10][20], temp;

printf("enter the string :");
scanf("%[^
]s", str);

/* reads into 2d character array */
for (i = 0;str[i] != ''; i++)
{
if (str[i] == ' ')
{
str1[k][j]='';
k++;
j=0;
}
else
{
str1[k][j]=str[i];
j++;
}
}
str1[k][j] = '';

/* reverses each word of a given string */
for (i = 0;i <= k;i++)
{
len = strlen(str1[i]);
for (j = 0, x = len - 1;j < x;j++,x--)
{
temp = str1[i][j];
str1[i][j] = str1[i][x];
str1[i][x] = temp;
}
}
for (i = 0;i <= k;i++)
{
printf("%s ", str1[i]);
}
}

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C Interview Questions

What is sorting in c plus plus?

0 Answers  


how can i sort numbers from ascending order and descending order using turbo c..

1 Answers  


main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above

0 Answers  


Is array name a pointer?

0 Answers  


void main(int argc,char *argv[],char *env[]) { int i; for(i=1;i<argc;i++) printf("%s",env[i]); }

3 Answers  






How do you use a pointer to a function?

0 Answers  


main() { char as[] = "\\0\0"; int i = 0; do{ switch( as[i++]) {case '\\' : printf("A"); break; case 0 : printf("B"); break; default : printf("C"); break; }} while(i<3); }

4 Answers   Vector, Vector India,


Write a c program to read a positive number and display it in words.? ex: 123=one two three help me....

2 Answers  


How can a string be converted to a number?

0 Answers  


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

0 Answers   TCS,


What is the difference between void main and main in c?

0 Answers  


what is difference between ANSI structure and C99 Structure?

1 Answers   Wipro,


Categories