-1

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.

ifox12
  • 9
  • 1
  • Please consider adding detailed information on the error to your question. – cel Jun 23 '15 at 14:22
  • 2
    @cel Do you really need more information to find this bug? This question is asked like 10 times per day. – Lundin Jun 23 '15 at 14:24
  • @Lundin, Oh right, this was not really necessary here. I just triaged the question and didn't even have a closer look at the code, I just noticed the missing error message. – cel Jun 23 '15 at 14:27

1 Answers1

0

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

Jeyaram
  • 9,158
  • 7
  • 41
  • 63