C program to copy string without using inbuilt functions

PROGRAM:

#include <stdio.h>
int main()
{
    //declarations
    char str[20],str2[20];
    int i=0;
    //read the string
    printf("Enter string to be copied\n");
    scanf("%s",str);
    //copy string to other string
    while(str[i]!='\0')
    {
        str2[i]=str[i];
        i++;
    }
    str2[i]='\0';
    printf("Entered string is %s\n",str);
    printf("Copied string is %s\n",str2);
    return 0;
}


OUTPUT:

Enter string to be copied
hello
Entered string is hello
Copied string is hello

Popular Posts