Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SIZE 80
- void newsentence(char a[], char b[], char c[], int n, int k);
- void array(int f, int s, int g, char buff[], char b[], char c[], int n, int k);
- int main()
- {
- char a[SIZE], b[SIZE], c[SIZE];
- int k;
- printf("Enter the sentence: ");
- gets(a);
- printf("nEnter the word which u want to replace: ");
- scanf("%s",b);
- printf("nEnter the new word: ");
- scanf("%s",c);
- int n =0;
- char *temp;
- temp =a;
- while((temp =strstr(temp,b))!= NULL){
- n++;
- temp++;
- k = strstr(temp,b)-b;
- }
- printf("The word appears %d times",n);
- newsentence(a,b,c,n,k);
- }
- void newsentence(char a[], char b[], char c[], int n, int k)
- {
- int f, s, g;
- char buff;
- f=strlen(a);
- s=strlen(b);
- g=strlen(c);
- strcpy(buff,a);
- array(f,s,g, buff,b,c,n,k);
- }
- void array(int f, int s, int g, char buff[], char b[], char c[], int n, int k)
- {
- int i,j;
- int q;
- q = k +s - 1;
- for(j = 0; k<=q ;k++, j++)
- {
- if(strcmp(buff[k],b[j])==0){
- strcmp(buff[k],c[i]);
- }
- }
- for(i = 0; i<SIZE;i++){
- printf("Yout new string is: %c",buff[i]);
- }
- }
Add Comment
Please, Sign In to add comment