strcpy runtime error / non-empty destination

592 views Asked by At

could you tell me why strcpy produces a runtime error here? Should the destination string be empty? And if so, why?

#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]) {
  char* input = "Nascartestdriver"; // strlen(input) == 16
  char* output = "asdfdhsghsdfasdf"; // strlen(output) == 16

  strcpy(output, input);
  printf("%s\n", output);
  return 0;
}

Thanks.

1

There are 1 answers

0
Jeyaram On

Because strcpy() tries to write on read-only section.