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


Please Help Members By Posting Answers For Below Questions

FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.

1533


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

756


Is main an identifier in c?

853


Does c have class?

848


What is meant by keywords in c?

846


What is getche() function?

817


Why is sprintf unsafe?

819


What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

807


How can I change their mode to binary?

904


What is #pragma statements?

848


Differentiate between declaring a variable and defining a variable?

831


What is calloc()?

835


What type of function is main ()?

812


What is malloc() function?

839


What is the ANSI C Standard?

1007