
Pointers 369
# include <string.h>
void main()
{
char src[20],dest[50],*ptr,*sr,f;
clrscr();
printf(“\n Enter a String :”);
gets(src);
printf(“\n Enter a Character to find in the text :”);
scanf(“%c”,&f);
sr=src;
ptr = memccpy(dest, sr, f, strlen(sr));
if(ptr)
{
*ptr = ‘\0’;
printf(“String up to that Character : %s\n”, dest);
}
else
printf(“The character wasn’t found\n”);
}
OUTPUT:
Enter a String : FUNCTIONS
Enter a Character to find in the text : T
String up to that Character : FUNCT
Explanation:
The memccpy() function copies the number of characters from the source string up to
the first occurrence of a given character. It returns ...