0
void cpy(char *s, char *t)  {         
while((*s = *t) != '\0') {
    s++;
    t++;
  }
}
void main() {
char *x;
char *y;
x="abc";
y="zzz";
cpy(x,y);

}

what it wrong with this function? is the part *s=*t wrong? always says "Access violation writing location"...

user2756494
  • 263
  • 1
  • 4
  • 7
  • 1
    You asked a similar question few minutes back:- http://stackoverflow.com/questions/18670912/assign-value-to-char-pointer-but-say-access-violation-writing-location – Rahul Tripathi Sep 07 '13 at 07:58
  • It's about don't modify string literals, as I answered in the other question of yours: http://stackoverflow.com/a/18670947/1009479 – Yu Hao Sep 07 '13 at 07:59
  • Dont modify the string literal as they are read only!!! – Rahul Tripathi Sep 07 '13 at 08:00

1 Answers1

0

The strings that you specify in quotas is constant strings and stores in read only memory. So after

x = "abc"

x points to read only memory area. And when you try to write there with cpy you get the exception.

Dmitry Poroh
  • 3,705
  • 20
  • 34