PROGRAM TO PRINT A STRING IN REVERSE ORDER USING malloc FUNCTION. | CODE WITH SHARAD

PROGRAM TO PRINT A STRING IN REVERSE ORDER USING malloc FUNCTION.

Written by Sharad Raj on 24th of May, 2018

C LANGUAGE PROGRAMS   DYNAMIC MEMORY ALLOCATION PROGRAMS   POINTER PROGRAMS   STRING PROGRAMS

PROGRAM CODE

#include<stdio.h>
#include<string.h>
#include<malloc.h>
main()
{
char *s,*s2;
int n,i,j;
s=(char*)malloc(1*sizeof(char));
s2=(char*)malloc(1*sizeof(char));
printf("Enter the string : ");
gets(s);
printf("\nSize of %s is %d\n",s,strlen(s));
j=0;
i=strlen(s)-1;
while(s[i]!='\0')
{
s2[j]=s[i];
i--,j++;
}
printf("\nString in reverse is : ");
for(i=0;i<strlen(s);i++)
{
printf("%c",s2[i]);
}
return 0;
}


Comments


Contact