Interview Questions and Answers :: Alcatel-Lucent
Home > Experience Archives > Alcatel-Lucent > Interview Question Set 1 > Discussion
3. write a program to reverse all the word in given sentence .
Ex. India is a Great Country.
Output: aidni si a taerg yrtnuoc.
Answer:
reverseWordString ( char * str)
{
int len, i, j;
len = strlen(str);
j = 0;
for (i = 0;i < len; i++)
if ( str[i] == ' ')
{
swap (str, j, i-1)
j = i+1;
}
void swap(char *str1, int start, int end)
{
int i = start;
char tmp;
for ( ; i<=end; i++, end--)
tmp = srt1[i];
str1[i]= str[end];
str[end] = tmp;
}
Aman
19 Jun, 2019 11:35 PM
reverseWordString ( char * str)
{
int len, i, j;
len = strlen(str);
j = 0;
for (i = 0;i < len; i++)
if ( str[i] == ' ')
{
swap (str, j, i-1)
j = i+1;
}
void swap(char *str1, int start, int end)
{
int i = start;
char tmp;
for ( ; i<=end; i++, end--)
tmp = srt1[i];
str1[i]= str[end];
str[end] = tmp;
}
{
int len, i, j;
len = strlen(str);
j = 0;
for (i = 0;i < len; i++)
if ( str[i] == ' ')
{
swap (str, j, i-1)
j = i+1;
}
void swap(char *str1, int start, int end)
{
int i = start;
char tmp;
for ( ; i<=end; i++, end--)
tmp = srt1[i];
str1[i]= str[end];
str[end] = tmp;
}
Report Error
Report Error
Please Login First Click Here