arrayofstring - Losing values with iterative realloc in C -
I am working in C with Netbeans8.0. To get a list of words, I have to read the files in an iterative approach. That is, a single file is read in an array of strings, and then add this array to an array.
zero merge_array (core ** a, int * m, four ** b, int n) {// ............. .... .......... * / Zero * tmp = realloc (A, (* M + N) * size (* A)); If (tmp == NULL) {perror ("merge -> could not be re-specified"); Exhaust (EXIT_FAILURE); } A = TMP; MEMSAT (A + (* M), 0, N * size (* A)); // ............. Copy String B in .............. * / int i, j = 0; For (i = * M; i & lt; ((M * + N); i ++) {size_t wlen = strlen (b [ja]); A [i] = maulok ((wlen + 1) * sizeof (char)); If (a [i] == tap) {false ("failed to repeat the string"); Exhaust (EXIT_FAILURE); } Mempi (A [I], B [J], VLN + 1); J ++; } (* M) = (* M) + N; // count printf reset ("confirm -% s,% d \ n", a [0], * m); }
The above function reads the contents of a file. In the above mentioned main work, it is called neatly and merged into an array called 'List List'. The main code is given below
char ** word list; Int termCount = 0; While (files [i]) {char ** word_array; Int wdCnt, A; Four * tmp = (four *) molk (strangel (path) * size (four)); Strcpy (tmp, path); Strcat (tmp, files [i]); Strcpy (files [i], tmp); Printf ("\ n \ n ******* Reading file% s ... \ n", files [i]); Word_array = getTerms_fscanf (files [i], & amp; a); // read content wdCnt = a; If (i == 0) // First list begins with terminal {{terminallist = (char **) malloc (wdCnt * sizeof (char *)); } Merge_array (word list, and wordcard, word_array, wdCnt); Printf ("check -% s,% d \ n", word list [0], wordcard); Free (word_array); ++ i; } Now the problem is that, after 1 two iterations, everything works well in the Inside function, but in the main values of the word list [0], [1] the word list [1] The junk is lost. 2 words read before the first file are lost. 3 recovery returns with failure on merge_array function call Output is
******* Reading F: / Netbeans C / Test Docs / doc1.txt ... Confirm - Tour, Check 52 - Excursion, 52 ******* Reading F: / Netbeans C / Test Docs / doc2.txt ... Confirm - Tour, 71 Check - Ôk'aÔk'a'œ € '' äk'aäk'aìk ' Aìk'aôk'aôk'aük'aük'ah "€, 71
I am not able to identify the problem with it .. Please help it ..
< / Div>
Comments
Post a Comment