Can't understand why I'm getting a segfault
<p>I'm using very little memory on the stack, and I have no recursion, and all my memory access is on the stack. So why am I getting a segfault?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;stdio.h&gt;
using namespace std;

int main(int argc, char *argv[]){
  FILE *file = fopen("test.cpp", "r");
  struct item{
    char *type;
    int price;
    bool wanted;
  };
  item items[100]; char *temp;
 if (file)
   cout &lt;&lt; "works up to here" &lt;&lt; endl;
  fscanf(file,
     "%s, %[for sale wanted], %d",
     items[0].type,
     temp,
     &amp;items[0].price);
}
</code></pre>

<p>It prints out</p>

<pre><code>works up to here
Segmentation fault (core dumped)
</code></pre>