which reveres da string like"hey i'm danish" to "danish i'm hey"
jst chek da code
#include <conio.h>
#include <stdio.h>
#include <string.h>
void rev_str (char str[],char out_str[],int len);
void substitute (char temp[],char str[]);
void rev(char str[],int len);
void main ()
{
clrscr ();
char in_str[100],out_str[100];
int len;
printf ("Enter a string:- ");
gets(in_str);
printf("\nEntered string is:- ");
puts (in_str);
len=strlen(in_str);
out_str[0]='\0';
rev_str(in_str,out_str,len);
printf("\n\nReversed String is:-");
puts (out_str);
getch ();
}
void rev(char str[],int len)
{
char temp[50];
int i,j;
for (i=0,j=len-1; i<len,j>=0; i++,j--)
temp[i]=str[j];
temp[i]='\0';
strcpy(str,temp);
}
void substitute (char temp[],char str[])
{
int temp_len=strlen(temp);
int i;
int str_len=strlen(str);
rev(temp,temp_len);
for (i=0;i<temp_len;i++)
str[i+str_len]=temp[i];
}
void rev_str (char in_str[],char out_str[],int len)
{
char temp[50]="";
int i=0,j=0;
for (i=len-1;i>=0;i--)
{
if(in_str[i]==' ')
{
substitute (temp,out_str);
j=-1;
for (int k=0;k<strlen(temp);k++)
temp[k]='\0';
}
else
temp[j] = in_str[i];
j++;
}
substitute (temp,out_str);
// out_str[len+1]='\0';
}
Edited by WingedPanther, 22 March 2010 - 04:44 AM.
add code tags (the # button)


Sign In
Create Account

Back to top









