Reverse a string word by word??

Answers were Sorted based on User's Feedback



Reverse a string word by word??..

Answer / vishnu948923

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
int n,i,j=0;
char str[100];
char str1[100];
clrscr();
puts("Enter string:");
gets(str);
n=strlen(str);
for(i=n-1;i>=0;i--)
{
if(str[i]==' ')
{
str1[j]='\0';
strrev(str1);
printf("%s ",str1);
j=0;
}
else
{
str1[j++]=str[i];

}
}
if(i==-1)
{
str1[j]='\0';
strrev(str1);

printf("%s ",str1);
}
getch();
}

//strtoke
//isvowel

Is This Answer Correct ?    24 Yes 10 No

Reverse a string word by word??..

Answer / anand

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char a[]="i am anand";

int x,len,y,z;
len=strlen(a);
z=len-1;
for(x=len-1;x>=0;x--)
{
if(a[x]==' '||x==0)
{
for(y=x;y<=z;y++)
{
printf("%c",a[y]);
}
z=x;
}
}
getch();

}

Is This Answer Correct ?    4 Yes 1 No

Reverse a string word by word??..

Answer / atul kumar rai

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100],temp1;
int i,j,len,temp;
printf("Enter any string : ");
gets(str);
len=strlen(str);
for(i=0,j=len-1;i<j;i++,j--)
{
temp1=str[i];
str[i]=str[j];
str[j]=temp1;
}
for(i=0; str[i]!=NULL; i++)
{
if(str[i+1]==' ' || str[i+1]==NULL)
{
for(temp=i; temp>=0 && str[temp]!=' '; temp--)
printf("%c",str[temp]);
printf(" ");
}
}
getch();
return 0;
}

Is This Answer Correct ?    1 Yes 0 No

Reverse a string word by word??..

Answer / santhosh

This Might Help You ...

http://user-interfaze.blogspot.com/2012/01/c-program-to-reverse-string-word-by.html

Is This Answer Correct ?    0 Yes 0 No

Reverse a string word by word??..

Answer / rohit_kamlakar

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int length,i,j;
char string[500];clrscr();
printf("Enter the string=");
gets(string);
length=strlen(string); int y=length,z=0;
for(i=length-1;i>=0;i--)
{
if(int(string[i])==32)
{ printf(" ");
for(j=i+1;j<length;j++)
{
printf("%c",string[j]);
z++;
}
length=y-z;
}

if(i==0)
{ j=i; printf(" ");
while(int(string[j])!=32)
{
printf("%c",string[j]);

j++;
}
}

}
getch();
}

Is This Answer Correct ?    3 Yes 4 No

Reverse a string word by word??..

Answer / vamsi

#include<stdio.h>
#include<conio.h>
void main()
{
char a[40],temp;
int count=0;
printf("enter the string :");
gets(a);
for(int i=40;a[i]!=a[1];i--)
printf (a[i]);
printf (a[1]);
}

Is This Answer Correct ?    1 Yes 9 No

Reverse a string word by word??..

Answer / dally

#include<stdio.h>
#include<conio.h>

int main()
{
char array1[] = "STRING FOR TESTNG";
char array2[20],i=0;
int count;
count = strlen(array);
for(count;count>1;count--)
{
array2[i]= array1[count];
i++;
}
printf("%s\n",array2);

}

Is This Answer Correct ?    0 Yes 8 No

Reverse a string word by word??..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
char a[40],temp;
int count=0;
printf("enter the string :");
gets(a);
for(int i=0;a[i]!='\0';i++)
count++;
for(i=0;a[i]!='\0';i++)
{
if(count>i)
{
temp=a[i];
a[i]=a[count-1];
a[count-1]=temp;
count--;
}
else
break;
}
printf("the reversed ones is : ");
puts(a);
getch();
}

thank u

Is This Answer Correct ?    9 Yes 21 No

Reverse a string word by word??..

Answer / guest

strrev(str1,str2);

Is This Answer Correct ?    1 Yes 17 No

Post New Answer

More C Interview Questions

which operator having highest precedence? a.)+ b.)++ c.)= d.)%

4 Answers  


What is the time and space complexities of merge sort and when is it preferred over quick sort?

0 Answers   Amazon,


If 4 digits number is input through the keyboard, Write a program to calculate sum of its 1st & 4th digit.

12 Answers   Google,


print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 1 2 3 4 5

7 Answers   IBM,


How arrays can be passed to a user defined function

0 Answers  






When is a void pointer used?

0 Answers  


Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.

3 Answers   SilverKey,


What is the difference between constant pointer and constant variable?

0 Answers   NIIT,


Hai why 'c' is the middle language

4 Answers  


What are the types of type specifiers?

0 Answers  


without using control structures and control structures find the max and min of given 2 nos

1 Answers   HCL,


What does d mean?

0 Answers  


Categories