Wednesday 9 October 2013

Filled Under: ,

Write a Program in C to Copy String

Objective : Write a Program in C to Copy String.

C language allows string handling with functions implementing operations on strings in the C standard library. Various operations, such as copying, concatenation, tokenization and searching are supported.

The only support for strings in the C programming language itself is that the compiler will translate a quoted string constant into a null-terminated string, which is stored in static memory. However, the standard C library provides a large number of functions designed to manipulate these null-terminated strings. These functions are so popular and used so often that they are usually considered part of the definition of C.

Here we discuss copy function on string.

PROGRAM CODE :

#include <stdio.h> 
#include <string.h>
#include <conio.h>
main()
{
char s1[20], s2[20];
clrscr();
printf(“----->COPY D STRING<----\n”);
printf("\nEnter string into s1: ");
gets(s1);
strcpy(s2, s1);
printf("\ns2: %s", s2);
getch();
}

0 comments:

Post a Comment