Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>About access violation:</h2> <blockquote> <p><strong>Access Violation</strong> is generally an attempt to access memory that the CPU cannot physically address.</p> </blockquote> <h2>Common causes:</h2> <blockquote> <p>Dereferencing NULL pointers . (<strong>THIS IS YOUR CASE see picture</strong>). You want to access to 0x000(NULL) location</p> <p>Attempting to access memory the program does not have rights to (such as kernel structures in process context) </p> <p>Attempting to access a nonexistent memory address (outside process's address space)</p> <p>Attempting to write read-only memory (such as code segment)</p> </blockquote> <p><strong>More :<a href="http://en.wikipedia.org/wiki/Segmentation_fault" rel="nofollow">more here in wikipedia</a></strong></p> <h2>How you should allocate (using your structure):</h2> <p>First You should allocate memory;<em>And dont forget you should write its free function,too</em></p> <p>Simple allocation would be such:</p> <pre><code> //instead I advice PCurrentData notation CurrentData AllCurrentData=malloc(NumProduct* sizeof *CurrentData); //memset so we can then check it with null memset(AllCurrentData,0,NumProduct* sizeof *CurrentData); int i,y; for(i=0;i&lt;NumProduct;i++){ //Noncontiguous allocation.Suits to string allocation,cause string lens differs AllCurrentData[i].data=malloc(COLUMNS*sizeof(char**)); memset(AllCurrentData[i].data,0,COLUMNS*sizeof(char**)); for(j=0;j&lt;COLUMNS;j++){ //this is just example //probably you want to allocate null terminating string int size=strlen(your_null_terminating_string)+1;//+1 for adding null,too AllCurrentData[i].data[j]=malloc(size*sizeof(char)); memcpy(AllCurrentData[i].data[j],your_null_terminating_string,size); } } </code></pre> <h2>Additionaly, What else is wrong in your code and proper way</h2> <p>Plus you are doing wrong. Looking at your structure you hold <code>char**</code>.But you try to access it with <code>2D [][]</code> array. <strong>Why we can not? Cause there is no guarantee that</strong> <code>char**</code> <strong>reference to continguous allocation, or only it done ,by manually, the way that compiler can access to it with [][]</strong>. Plus for <code>char**</code> mostly allocation done with noncontinguous way.cause strings len differs</p> <p>So Note these:</p> <p><code>char**</code> <strong>is not equal to</strong> 2D array <code>char v[][] array</code>. So doing <code>AllCurrentData[i].data[j][k]</code> is <strong>wrong</strong> to address <code>char**</code>.</p> <p>only <code>char*</code> can be equally treated as one dimensional <code>char v[]</code> array. <code>char[]</code> decay to <code>char*</code></p> <p>So accessing should be done this way:</p> <pre><code>#define NULL 0 if(AllCurrentData[i]!=NULL &amp;&amp; AllCurrentData[i].data[j]!=NULL){ char* str=AllCurrentData[i].data[j]; if(str!=NULL) while (str[k]!='\0'){ printf("%c ",str[k]);++k; } } /*or while (*str){ printf("%c ",*str);++str; } */ /*but actualy you can print null terminating string directly (assuming you wanted this) if(str!=NULL) printf("%s",str); */ </code></pre> <p><a href="http://www.lysator.liu.se/c/c-faq/c-2.html" rel="nofollow">more to learn about arrays and pointers</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload