title: Reading data from a file, only alpha characters
body: <p>I'm working on a program for school right now in c and I'm having trouble reading text from a file.  I've only ever worked in Java before so I'm not completely familiar with c yet and this has got me thoroughly stumped even though I'm sure it's pretty simple.  </p>
  
  <p>Here's an example of how the text can be formatted in the file we have to read: </p>
  
  <p>boo22$Book5555bOoKiNg#bOo#TeX123tEXT(JOHN)</p>
  
  <p>I have to take in each word and store it in a data structure, and a word is only alpha characters, so no numbers or special characters.  I already have the data structure working properly so I just need to get each word into a char array and then add it to my structure. It has to keep reading each char until it gets to a non-alpha char value.  I've tried looking into the different ways to scan in from a file and I'm not sure what would be best for my scenario. </p>
  
  <p>Here's the code I have right now for my input:</p>
  
  <pre><code>char str[MAX_WORD_SIZE];
  char c;
  int index = 0;
  
  while (fscanf(dictionaryInputFile, "%c", c) != EOF) //while not at end of file
  {   
      if (isalpha(c)) //if current character is a letter
      {
          tolower(c); //ignores case in word
          str[index] = c; //add char to string
          index++;
      }
      else if (str[0] != '\0') //If a word
      {
          str[index] = '\0'; //Make sure no left over characters in String
          dictionaryRoot = insertNode(str, dictionaryRoot); //insert word to dictionary
          index = 0; //reset index
          str[index] = '\0'; //Set first character to null since word has been added
      }
  }
  </code></pre>
  
  <p>My thinking was that if it doesn't hit that first if statement then I have to check if str is a word or not, that's why it checks if the 0 index of str is null or not.  I'm guessing the else if statement I have is not right though, but I can't figure out a way to end the current word I'm building and then reset str to null when it's added to my data structure.  Right now when I run this I get a segmentation fault if I pass the txt file as an argument.</p>
  
  <p>I'd just like to know if I'm on the right track and if not maybe some help on how I should be reading this data.</p>
  
  <p>This is my first time posting here so I hope I included everything you'll need to help me, if not just let me know and I'd be happy to add more information.</p>