Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Friday, May 30, 2014

string copying in c programming

C program to copy a string

#include<stdio.h>
#include<string.h>
#include<conio.h> 
void main()
{
   char source[] = "C program";
   char destination[50];
   clrscr();
   strcpy(destination, source);
   printf("Source string: %s\n", source);
   printf("Destination string: %s\n", destination);
   getch();
}

c program to copy a string using pointers

#include<stdio.h>
#include<conio.h>
#include<string.h> 
void copy_string(char*, char*);
void main()
{
    char source[100], target[100];
    clrscr();
    printf("Enter source string\n");
    gets(source);
    copy_string(target, source);
    printf("Target string is \"%s\"\n", target);
    getch();
}
void copy_string(char *target, char *source)
{
   while(*source)
   {
      *target = *source;
      source++;
      target++;
   }
   *target = '\0';
}

No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC