copies string source to string target. This is an array subscript based version: - C String

C examples for String:String Function

Description

copies string source to string target. This is an array subscript based version:


void strcpy(char *target, char *source)
{
  int j = 0;
  while((target[j] = source[j]) != '\0')
    j++;
}

Demo Code

/* Count spaces */
#include <stdio.h>

void strcpy(char *target, char *source)
{
   int j = 0;/*  ww  w . j  av a2  s  .c o m*/
   while ((target[j] = source[j]) != '\0')
      j++;
}


int main(void)
{
   char *str = "this is a  test";
   char s[80];

   strcpy(s, str);

   puts(s);

   return 0;
}

Result


Related Tutorials