C program – Copy the contents of one string to another string using pointer

by Nideesh C on April 18, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
void stcpy(char *str1, char *str2);
void main()
{
char *str1, *str2;
clrscr();
printf(“nnt ENTER A STRING…: “);
gets(str1);
stcpy(str1,str2);
printf(“nt THE COPIED STRING IS…: “);
puts(str2);
getch();
}
void stcpy(char *str1, char *str2)
{
int i, len = 0;
while(*(str1+len)!=’′)
len++;
for(i=0;i<len;i++)
*(str2+i) = *(str1+i);
*(str2+i) = ‘′;
}

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program To reverse the given string
  2. C Program to accepts two strings and compare them. Finally it prints whether both are equal, or first string is greater than the second or the first string is less than the second string
  3. C program – Morse code to text conversion and vice-versa.
  4. C Program to accept two strings and concatenate them i.e.The second string is appended to the end of the first string
  5. C program to read two strings and concatenate them (without using library functions). Output the concatenated string along with the given string

Leave a Comment

Previous post:

Next post: