Pointers 311
sr=src;
ptr = memccpy(dest,sr,f,strlen(sr));
if(ptr)
I
*p tr='0 ';
printf ("String tip to that Character: %sn", dest);
}
else
printf(//The character wasn't foundn");
I
QmZLTT;
Enter a String: FUNCTIONS
Enter a Character to find in the text: T
String up to that Character: FUNCT
Explanation Thememccpy () function copies number of characters from the source string up to first
occurrence of the given character. It returns to pointer if the given character is found otherwise it
returns NULL.
9.36 Write a program to read two strings through the keyboard^ Replace the contents of
second string with the first string. The length of the first string should be less than
second string.
#include <stdio.h>
#include <string.h>
# include <canio.h>
void main()
{
static char src[20],dest [20];
char *ptr;
clrscr();
printf ("nEnter a Source String:");
gets(src);
printf ("nEnter a Destination String:");
gets(dest);
printf("nnDestination before memcpy: %sn", dest);
ptr= memcpy(dest, src, strlen(src));
if(ptr)
printf("Destination after memcpy: %sn", dest);
else
printf("memcpyfailedn");
}
OUTPUT :
Enter a Source String: Tomorrow
Enter a Destination String: Today is Sunday
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.197.136