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 |
write a program to swap bits in a character and return the value prototype of function char fun (char a, charb flag c) where fun returns a char, char a is a the value char b is the bit to be changed and flag c is the bit value for eg: x=fun(45,7,0) since 45 is 0010 0101 and ow x should contain the value 65 (0110 0101)
1 Answers Bosch, College School Exams Tests,
Give a method to count the number of ones in a 32 bit number?
what is the different between data structure and data type?
write C code to reverse a string such that if i/p is "abc defg hij klmno pqrs tuv wxyz" and the o/p should be "cba gfed jih onmlk srqp vut zyxw"
WHAT IS HEADER?
What is typeof in c?
Do variables need to be initialized?
Find Index of least significant bit set in an Integer. ex. int value is say 10001000 results should be 4.
What is pragma c?
Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..???
pascal triangle program
code snippet for creating a pyramids triangle ex 1 2 2 3 3 3