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

What are loops in c?

0 Answers  


what is the function of pragma directive in c?

0 Answers  


tell me the full form of c?

2 Answers  


wite a programme in c to linear search a data using flag and without using flags?

3 Answers   TCS,


what is c++ programming?

3 Answers   TCS,


where do we use volatile keyword?

1 Answers  


What are the various types of control structures in programming?

0 Answers  


What does. int *x[](); means ?

0 Answers   Wilco,


Which of these statements are false w.r.t File Functions? i)fputs() ii)fdopen() iii)fgetpos() iv)ferror() A)ii B)i,ii C)iii D)iv

6 Answers   Accenture,


What is an anonymous union and where to apply that ?

3 Answers   HP,


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,


Can we change the value of static variable in c?

0 Answers  


Categories