Saturday, August 4, 2012

Reverse all words and string using pointer

Q. Write a C program to accept a string from user and reverse all words with string using pointer.


for example:


string: This Is A Good Blog
result: golB dooG A sI sihT


Ans.

/*c program for accept string and print it all words with string in reverse order using pointer*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char str[30];
 char *p;
 printf("Enter any string: ");
 gets(str);
 printf("\n-- Reversing string with words & character --\n\n");
 for(p=str; *p!='\0'; p++);
 for(p--; p>=str; p--)
    printf("%c",*p);
 getch();
 return 0;
}


/************Output************/


Output of reverse all words and string using pointer C program
Screen shot for reverse all words and string
using pointer C program

No comments:

Post a Comment