prev


Character Arrays - String manipulations:

99.sed command - search and replace string(16.05.2010)

/*
Program# 99
date : 10-01-2009
Search and Replace the Pattern
*/

#include <stdio.h>
main(){
char a[100],b[100],c[100],d[100];
int i,j,k,l,m;

i=0;
scanf("%c",&a[i]);
while(a[i]!='$'){
i++;
scanf("%c",&a[i]);
}
a[i]='\0';
//search pattern
j=0;
scanf("%c",&b[j]);
while(b[j]!='$'){
j++;
scanf("%c",&b[j]);
}
b[j]='\0';
//replacement pattern
k=0;
scanf("%c",&c[k]);
while(c[k]!='$'){
k++;
scanf("%c",&c[k]);
}
c[k]='\0';

i=0;l=0;
while(a[i]!='\0'){
j=0;
k=i;

while((b[j]==a[k]) && (b[j]!='\0')){
j++;
k++;
}

if(b[j]=='\0'){
i=k;
m=0;
while(c[m]!='\0'){
d[l]=c[m];
m++;
l++;
}
}
else{
d[l]=a[i];
i++;
l++;
}
}
d[l]='\0';
printf("\na=%s \nb=%s \nc=%s \nd=%s",a,b,c,d);
}



next
blog comments powered by Disqus