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************/
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************/
Screen shot for reverse all words and string using pointer C program |
Comments
Post a Comment