Pass by reference 2D dynamically allocated double array in C -


I am trying to convert my string into a dynamic array of doubles. Each location in my string represents a column, each ";" Represents a new line when this code runs, it only works for * F [0] [cola]. When it gets for * F [1] [color] then gives me "unneeded exception" at 0x00e4483c in CCODA XE: 0xC0000005: Access violation location 0xcccccccc to read. Anyone know why?

  Zero main (zero) {double ** f = faucet; F = Molec (line * size (double *)); For (m = 0; m; lt; row; m ++) {f [m] = maulok (cola * sized (double)); } FParser (string, & amp; f); (M = 0; M & LT; RFF; M ++) for free (F [M]); Free (F); } Zero FParser (four string [256], double *** f) {while (dummyChar_ptr! = NULL) {dummyChar_ptr = strtok (dummyChar_ptr, ""); While ((dummyChar_ptr)! = Null) {* F [row] [cola] = etf (dummy CHRP); Dummy CRPR = Strotok (Null, ""); Col ++; } Col = 0; Line ++; Strcpy (dummyChar, string); Dummy CRPR = Strottok (hopper, ";"); For (x = 0; x  

[] is a high priority In C in unary * , therefore * F [row] [color] is actually * (f [row] [color]) And you're indexing in the wrong storage location.

(* F) [row] [cola]) Try .

Incidentally, there is no reason for this FParser to take a double *** anyway. F is already an indicator; That's just close. The only reason is that you need to use an extra layer of indirection, if it is necessary to modify FParser key F .

Other miscellaneous bits of advice:

  • Check that malloc are successful.
  • Avoid global variables. Do not use
  • strcpy unless you have not checked that the source string will overflow the destination buffer.
  • Function parameter Four strings [256] does not really guarantee that the input logic is an array of 256 (or more) elements, so this is notorious for the IMO as well as < The code can be four * string .

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -