STRCPY():-
String
copy function copies the string from source to destination. The strings
may not overlap, and the destination string dest must be large enough to receive the copy. Beware of buffer overruns. string copy return a pointer to the destination string dest.
syntax:-
char *strcpy(char
*to, const char *from);
using strcpy :-
#include<stdio.h>
#include<string.h>
main()
{
char
a[]="Google";
char b[15];
int
i=0;
strcpy(b,a);
for(i=0;b[i]!=0;i++)
{
printf("%c",b[i]);
}
}
With out using Strcpy:-
int main()
{
char
str1[12]="Google";
char
str2[20];
int i=0;
while(str1[i]!='\0')
{
str2[i] =
str1[i];
i++;
}
str2[i]='\0';
printf("copied string=\t%s\n",str2);
}
Out Put:-
copied String = google
-----------------------------------------------------------------------------------------
More details about C interview questions and programs: http://learnclanguage4.blogspot.com/
No comments:
Post a Comment