:
char* num = (char*)malloc(100);
num .
num = "123456";
In this line, you used num when you declared it as a string. This is a violation of segmentation and, therefore, segregation. Preferred (correct) syntax for your code:
char num[100];
strcpy(num,"123456");
OR
char* num = (char*)malloc(100);
strcpy(num,"123456");
OR
char num[100]={'1','2','3','4','5','6'};
Any of them will do your job.
source
share