Interview can ask write your own program or user defined function of strlen(), strcpy(), strncpy().
User defined function of strlen()
strlen is used to find the length of a string.
Prototyoe of strlen() function : size_t strlen(const char * str);
Program of strcpy()
#include <stdio.h>
int len(const char *str)
{
int count=0;
while(*str!=’\0′)
{
count++;
str++;
}
return(count);
}
void main()
{
char str[25];
int length = 0;
printf(“Enter any string = “);
gets(str);
/* Own string length function call */
length = len(str);
printf(“length of string is = %d”,length);
}
Output:
$ ./a.exe
Enter any string = gyantoday.com
length of string is = 13
Try to write user defined function of strcpy(), strncpy and strcmp() by yourself.
User defined function of strcpy()