Guest User

Untitled

a guest
Dec 14th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #define SIZE 80
  2.  
  3. void newsentence(char a[], char b[], char c[], int n, int k);
  4. void array(int f, int s, int g, char buff[], char b[], char c[], int n, int k);
  5.  
  6. int main()
  7. {
  8. char a[SIZE], b[SIZE], c[SIZE];
  9. int k;
  10.  
  11. printf("Enter the sentence: ");
  12. gets(a);
  13. printf("nEnter the word which u want to replace: ");
  14. scanf("%s",b);
  15. printf("nEnter the new word: ");
  16. scanf("%s",c);
  17.  
  18. int n =0;
  19. char *temp;
  20. temp =a;
  21.  
  22. while((temp =strstr(temp,b))!= NULL){
  23. n++;
  24. temp++;
  25. k = strstr(temp,b)-b;
  26. }
  27. printf("The word appears %d times",n);
  28.  
  29. newsentence(a,b,c,n,k);
  30. }
  31.  
  32. void newsentence(char a[], char b[], char c[], int n, int k)
  33. {
  34. int f, s, g;
  35. char buff;
  36.  
  37. f=strlen(a);
  38. s=strlen(b);
  39. g=strlen(c);
  40.  
  41. strcpy(buff,a);
  42.  
  43. array(f,s,g, buff,b,c,n,k);
  44. }
  45. void array(int f, int s, int g, char buff[], char b[], char c[], int n, int k)
  46. {
  47. int i,j;
  48. int q;
  49. q = k +s - 1;
  50.  
  51. for(j = 0; k<=q ;k++, j++)
  52. {
  53. if(strcmp(buff[k],b[j])==0){
  54. strcmp(buff[k],c[i]);
  55. }
  56. }
  57.  
  58. for(i = 0; i<SIZE;i++){
  59. printf("Yout new string is: %c",buff[i]);
  60. }
  61. }
Add Comment
Please, Sign In to add comment