Why does this code to modify a string not work?
问题 With c-style strings, how do you assign a char to a memory address that a character pointer points to? For example, in the example below, I want to change num to "123456", so I tried to set p to the digit where '0' is located and I try to overwrite it with '4'. Thanks. #include <stdio.h> #include <stdlib.h> int main() { char* num = (char*)malloc(100); char* p = num; num = "123056"; p = p+3; //set pointer to where '4' should be p = '4'; printf("%s\n", num ); return 0; } 回答1: That code won't