Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the best way to store flag values in a program?

1032


the question is that what you have been doing all these periods (one year gap)

2043


Explain how can a program be made to print the name of a source file where an error occurs?

1160


How do you use a pointer to a function?

1052


When should volatile modifier be used?

973


What does %c mean in c?

1039


Explain the use of 'auto' keyword in c programming?

1086


What is a program flowchart and explain how does it help in writing a program?

1266


What is the use of void pointer and null pointer in c language?

1088


Differentiate between static and dynamic modeling.

1069


Which built-in library function can be used to match a patter from the string?

1264


What is the importance of c in your views?

1127


What is #error and use of it?

1225


what will be maximum number of comparisons when number of elements are given?

1869


Explain how do you generate random numbers in c?

1059