Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define SIZE 40
- char *strncpy2(char *string1, char *string2);
- int main(void){
- int x;
- char string1[SIZE]="boy am i awesome";
- char string2[]=". you sure are";
- char *ptr=strncpy2(string1, string2);
- for (x=0; x<=sizeof(string1); x++){
- printf("%c", *ptr);
- ptr++;
- }
- printf("\n");
- return 0;
- }
- char *strncpy2(char *string1, char *string2){
- char *ptr=string1;
- int length=(int)strlen(string1);
- int i, count=0;
- for(i=length; i<=SIZE; i++){
- *(ptr+i)=string2[count];
- count++;
- if(count==strlen(string2))
- break;
- }
- return ptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement