write an algorithm to get a sentence and reverse it in the
following format:
input : I am here
opuput: Here Am I
note: first letter of every word is capiatlised
Answer Posted / vignesh1988i
here using pointers we can easily do the above..........
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
char a[50],*ptr,*pointer;
int n,i,j,k;
printf("enter the string:");
gets(a);
for(i=0;a[i]!='\0';i++)
n++;
pointer=(char*)malloc((n+1)sizeof('2'));
j=0;
for(i=0;a[i]!='\0';)
{
if(a[i]==' ')
{
*(pointer+(n-j-1))=a[i];
i++; j++;
}
else
{
ptr=&a[i];
for(k=0;a[i+1]!=' '&&a[i+1]!='\0';k++)
i++;
for(k=0;k<((&a[i]-ptr)+1);k++)
{
*(pointer+(n-j-1))=*(ptr+(&a[i]-ptr)-k);
j++;
}
}
i++;
}
*(pointer+(n+1))='\0';
for(i=0;i<n;i++)
printf("%c",*(pointer+i));
getch();
}
thank u
| Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
How many bytes are occupied by near, far and huge pointers (dos)?
Is it better to bitshift a value than to multiply by 2?
What is malloc() function?
Not all reserved words are written in lowercase. TRUE or FALSE?
What are linker error?
Describe wild pointers in c?
Are there constructors in c?
What are the advantages and disadvantages of c language?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
What is the value of h?
What is the difference between union and structure in c?
What are header files in c?
What is the benefit of using #define to declare a constant?
What does sizeof int return?