Monday, June 18, 2012

To copy a string


/* Program to copy a string */

#include<stdio.h>

#include<conio.h>

void main()

{

  char str1[20],str2[20];

  int i;

  clrscr();

  printf("Enter any string:");

  gets(str2);

  for(i=0;str2[i]!='\0';i++)

    str1[i]=str2[i];

  str2[i]='\0';

  printf("\nCopied string:");

  puts(str1);

  getch();

}

 

OUTPUT

Enter any string:have a nice day!

 

Copied string:have a nice day!

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.