mihainan

Examen - PC

Sep 7th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. /*
  2.     Program implementat de Nan Mihai
  3.     Pregatire examen restanta PC - 2014
  4. */
  5.    
  6. char *strdel(char *p, int n) {
  7.     char *aux = strdup(p + n);
  8.     strcpy(p, aux);
  9.     return p;
  10. }
  11.  
  12. char *strins(char *p, char *s) {
  13.     char *aux;
  14.     aux = strdup(p);
  15.     strcpy(p, s);
  16.     strcat(p, aux);
  17.     return p;
  18. }
  19.  
  20. int main() {
  21.     char text[100], cuv1[100], cuv2[100], *p, *aux;
  22.     gets(text);
  23.     gets(cuv1);
  24.     gets(cuv2);
  25.     p = strstr(text, cuv1);
  26.     while(p)
  27.     {
  28.         aux = p;
  29.         strdel(aux, strlen(cuv1));
  30.         strins(aux, cuv2);
  31.         aux += strlen(cuv2);
  32.         p = strstr(aux, cuv1);
  33.     }
  34.     printf("%s", text);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment