c - Realloc, char**, segfault -
is a function, it is add_lexem and adds an element (parentheses) at the end of the specified array. If no one left the memory, it allocates some extra memory (100 * size * (* four *). This function is caused by segfault, which is the problem.
#include & lt ; String.h & gt; #include & lt; stdlib.h & gt; #include & lt; stdio.h & gt; zero add_lexem (core ** lexam, int * lexmsac, int * lexem_en, const char * Lexem) {if (* lexem_n & gt; = * lexemsc) {lexems = realloc (Lexmas, Psychof (four *) * (* Lexmsi + 100)) * Lexmsk + = 100;} char * for_adding = malloc (size Character) * Strangel (lexem); Strcpy (for_addin G, lexem; lexem [lexem_en] = for_ adding; (* lexem_n) ++;} int main (zero) {char ** d = malloc (sizeof (char *) * 2); int lexmsis = 2; int lexem_n = 0; ad_cllex (D, and lexmsac, and lexem_en, "MEEE"); Printf ("% s \ n", D [0]); Ad_cllex (D, and Lexmsac, and Lexem_N, "Bark"); Printf "% S \ n", D [1]); // in this place lexem_n is equal to lexemsc add_lexem (D, and lexamsak, and lexem_en, "corkk"); printf ("% s \ n", d [2] ]); Return 0; } should be output
meve burk quaker but this is
< code> Mayo Burke segmentation fault (core dump)
Three-star-programming: one Insert whatever you have inside the straight:
Comments
Post a Comment