Reverse a string word by word??
Answers were Sorted based on User's Feedback
#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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
The variables are int sum=10,SuM=20; these are same or different?
what is difference between overriding and overloading?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
When is an interface "good"?
How can I call fortran?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
5 Answers TCS, Vimukti Technologies,
Where are c variables stored in memory?
Why doesnt long int work?
What are external variables in c?
how can make variable not in registers
#include <stdio.h> int main() { if ("X" <"x") printf("X smaller than x "); } my question is whats the mistake in this program? find it and please tell me..
how to print value of e(exp1)up to required no of digits after decimal?