Underlying Concept: String manipulation
#include<stdio.h>
#include<stdlib.h>
int sub_reverse(char *s,char *r,char *t)
{
int i=0;
while(s[i]!=0)
{
if(s[i]==r[0])
break;
i++;
}
char temp;
while(s<t)
{
temp=*s;
*s=*t;
*t=temp;
s++;
t--;
}
}
int main()
{
char *string,*sub,*end;
unsigned u,pos1,pos2;
printf("\n enter size of string:");
scanf("%u",&u);
string=(char *)malloc(u*sizeof(char));
printf("\n enter the string:");
scanf("%s",string);
printf("\n What is the position of first character of substring:");
scanf("%u",&pos1);
printf("\n What is the position of last character of substring:");
scanf("%u",&pos2);
sub=string+pos1;
end=string+pos2;
sub_reverse(string,sub,end);
printf("\nNew string is:%s",string);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int sub_reverse(char *s,char *r,char *t)
{
int i=0;
while(s[i]!=0)
{
if(s[i]==r[0])
break;
i++;
}
char temp;
while(s<t)
{
temp=*s;
*s=*t;
*t=temp;
s++;
t--;
}
}
int main()
{
char *string,*sub,*end;
unsigned u,pos1,pos2;
printf("\n enter size of string:");
scanf("%u",&u);
string=(char *)malloc(u*sizeof(char));
printf("\n enter the string:");
scanf("%s",string);
printf("\n What is the position of first character of substring:");
scanf("%u",&pos1);
printf("\n What is the position of last character of substring:");
scanf("%u",&pos2);
sub=string+pos1;
end=string+pos2;
sub_reverse(string,sub,end);
printf("\nNew string is:%s",string);
return 0;
}





0 comments