whining
Say this error is very hateful Ah, yesterday afternoon has been, eat dinner back again, always get back to the dormitory when, think of try again, unexpectedly found the wrong. My program is a book of routines, not full letter ah. Just a quick note.
cause of the error
I was prompted by the Internet "nothing more than a few details of the reasons, such as: the declaration of the pointer but did not initialize, the result of the subsequent indirect reference", for example,
Char *p;
Char test[]= "Hello";
strcpy (p,test);
The passage of words from; http://www.cnblogs.com/gudai/archive/2006/06/27/436601.html
And my mistake is this: when I do a shared memory experiment, there's a paragraph
Char *buff;
Char *shm_addr;
Fgets (Buff,2048,stdin); there's no mistake in here.
strncpy (Shm_addr,buff,strlen (buff)); There's been a mistake.
I compile without errors, runtime, when typing Hello, prompts for segmentation fault (core dumped), as shown below
Inspired by the above, I will char *buff; One sentence modified into Char buff[20]; No errors, and the program is running normally.
Today, a careful analysis of the reason, just understand that I have defined the pointer buff, but in the 4th sentence using strlen (buff), to find the length of the type of pointer, this guy's length I did not give it definition, not overflow is strange. Modified to char buff[20], Buff is the first address of the array, with a length of 20. So there won't be any mistakes.