These two lines:
char* num = (char*)malloc(100);
num = "123456";
have the following effect.
The first allocates 100 bytes and sets num
to point to those bytes.
The second changes num to point to the string "123456" which is almost certainly in read-only memory.
Any attempt to change the contents of read-only memory will result in a segmentation violation. You need to copy the string into the malloc
'd num
before attempting to change it, with:
strcpy (num, "123456");
That's the line you should have where you currently have:
num = "123456";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…