Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define maxlength 256
  6.  
  7. void reversePuts(const char s[]);
  8. char *strprecat(const char *s1, char *s2);
  9.  
  10. int main(void)
  11. {
  12.     char s1[maxlength] = "pre string.";
  13.     char s2[maxlength] = "ANIMATION";
  14.  
  15.     putchar('\n');
  16.     puts(s1);
  17.     reversePuts(s1);
  18.  
  19.     puts(s2);
  20.     reversePuts(s2);
  21.    
  22.     putchar('\n');
  23.     puts(s1);
  24.     puts(s2);
  25.     putchar('\n');
  26.     puts(strprecat(s1,s2));
  27.     putchar('\n');
  28.     puts(s1);
  29.     puts(s2);
  30.  
  31.     return 0;
  32. }
  33.  
  34. void reversePuts(const char s[])
  35. {
  36.     const char *c = s + strlen(s);
  37.     while (c > s)
  38.         putchar(*(--c));
  39.     putchar('\n');
  40. }
  41.  
  42. char *strprecat(const char *s1, char *s2)
  43. {
  44.     int i, l1 = strlen(s1), l2 = strlen(s2);
  45.     if (l1 + l2 >= maxlength)
  46.         return 0;
  47.     for (i = l2; i >= 0; i--) // the null character at the end of s2 is moved too.
  48.         s2[i + l1] = s2[i];
  49.     for (i = 0; i < l1; i++)
  50.         s2[i] = s1[i];
  51.     return s2;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement