c program string funtion
C program to copy string without using strcpy() function :
We can use inbuilt strcpy() function to copy one string to other but here, this program copies the content of one string to another manually without using strcpy() function.
Approach:Here we are giving one string in input and then with the help of for loop we transfer the content of first array to the second array.
- Error : If destination string length is less than source string, entire string value won’t be copied into destination string.
- For example, consider destination string length is 20 and source string length is 30. Then, only 20 characters from source string will be copied into destination and remaining 10 characters will be truncated.
Required knowledge:
program :
#include<stdio.h>
int main()
{
char str[100]="atikur rahamn";
char str3[100];
int i;
for(i=0;str[i]!='\0';i++){
str3[i]=str[i];
}
str3[i]='\0';
printf("str : %s\n",str);
printf("str3 : %s ",str3);
return 0;
}
OUTPUT :

No comments