title: How to identify Segmentation Fault?
body: <p>I’m trying to define a function that accepts a file pointer of a file that’s already been opened and a pointer to a structure of type String which I have defined as such:</p>
  
  <pre><code>typedef struct string {
    char* char_arr;
    int capacity;
    int size;
  } String;
  </code></pre>
  
  <p>This should return 1 if the function was able to read from the file and place the first word into the String, and 0 if not. When I ran it however, I receive a “segmentation fault” message. I read that this involved the misuse of a pointer, but I am having trouble finding where that occurred.</p>
  
  <pre><code>int string_extraction(FILE* pFile, String* pString){
    char* c_string;
    int i;
    char c;
  
    fscanf(pFile, " %c", &amp;c);
  
    for(i=0; !isspace(c) &amp;&amp; c != EOF; i++){
    c_string[i] = c;
    c = fgetc(pFile);
    }
    ungetc(c, pFile);
  
    pString = (String*)malloc(sizeof(String));
    if (pString != NULL) {
      pString-&gt;size = i;
      pString-&gt;capacity = i+1;
      pString-&gt;char_arr = (char*)malloc(sizeof(char) * (pString-&gt;capacity));        
      if (pString-&gt;char_arr == NULL) {
        free(pString);
        pString = NULL;
      } else pString-&gt;char_arr = c_string;
    }
  
    if(pString == NULL)
      return 0;
    return 1;
  }
  </code></pre>