Advertisement
horselurrver

Ch11 Ex6

Aug 8th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define SIZE 40
  5. char *strncpy2(char *string1, char *string2);
  6. int main(void){
  7.     int x;
  8.     char string1[SIZE]="boy am i awesome";
  9.     char string2[]=". you sure are";
  10.     char *ptr=strncpy2(string1, string2);
  11.     for (x=0; x<=sizeof(string1); x++){
  12.         printf("%c", *ptr);
  13.         ptr++;
  14.     }
  15.     printf("\n");
  16.     return 0;
  17. }
  18.  
  19. char *strncpy2(char *string1, char *string2){
  20.     char *ptr=string1;
  21.     int length=(int)strlen(string1);
  22.     int i, count=0;
  23.     for(i=length; i<=SIZE; i++){
  24.         *(ptr+i)=string2[count];
  25.         count++;
  26.         if(count==strlen(string2))
  27.             break;
  28.     }
  29.  
  30.     return ptr;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement