Q:

Creating a function to copy a string

0

Creating a function to copy a string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
void copy_string(char [], char []);

int main() {
  char s[1000], d[1000];
   
  printf("Input a string\n");
  gets(s);

  copy_string(d, s);
  printf("The string: %s\n", d);

  return 0;
}

void copy_string(char d[], char s[]) {
  int c = 0;
   
  while (s[c] != '\0') {
    d[c] = s[c];
    c++;
  }
  d[c] = '\0';
}

Output of the program:

Before copying, the string: What can I say about my programming skills?
Input a string to copy
My programming skills are improving.            
After copying, the string: My programming skills are improving.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now