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 are two dimensional arrays alternatively called as?

0 Answers  


How we can write a value to an address using macro..?

0 Answers   Tata Elxsi,


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

0 Answers  


What is define directive?

0 Answers  


HOW TO SWAP TWO NOS IN ONE STEP?

16 Answers   Satyam,






write a pgm to print 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1

3 Answers  


What is #define used for in c?

0 Answers  


What does d mean?

0 Answers  


When we use void main and int main?

0 Answers  


Program to simulate second clock

2 Answers  


Why is c called c?

0 Answers  


Why does notstrcat(string, "!");Work?

0 Answers  


Categories