This could easily lead to writing beyond the end of arrays. Note that the for loop inside the addleft() function is dangerous as the char* contained within s are not necessarily of the same length. To correct, you could use strdup() if it is available otherwise malloc() and strcpy(): /* Instead of: This is undefined behaviour and a probable segmentation fault. You need to either dynamically allocate memory for ele or declare a local array and prevent buffer overrun when using scanf(): char ele Īdditionally, the function addleft() is using strcpy() on s, which is an array of char* and each of the char* in the array is unitialised. Ele is an uninitialised char* and has no memory associated with it and scanf() will be attempting to write to it causing undefined behaviour, a segmentation fault is probable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |