lolamontes69

K+R Exercise5_3

Sep 7th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void strcat1(char *s, char *t);
  4.  
  5. int main()
  6. {
  7.     char n[300]="cute little ";
  8.     char m[]="froggy";
  9.     char o[300]="Another ";
  10.  
  11.     strcat1(&n[0],&m[0]);
  12.     printf("%s",n);
  13.     puts(" ");
  14.  
  15.     strcat1(&o[0],&n[0]);
  16.     printf("%s",o);
  17.     puts(" ");
  18.     return(0);
  19. }
  20.  
  21. /* strcat1: concatenate t to the end of s, s must be big enough */
  22. void strcat1(char *s, char *t)
  23. {
  24.     int i=0;
  25.     int j=0;
  26.  
  27.     while(s[i]!='\0')      /*find end of s */
  28.         i++;
  29.     while(s[i++] = t[j++]) /* copy t */
  30.         ;
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment