Syntax Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PlainLazy
    New Member
    • Mar 2008
    • 2

    Syntax Error

    I've been given a nice C programme to make from my lecturer at uni. I've got to open a file then find out the average word length and frequency of each letter.

    I've written it all and gotten rid of most of the errors apart from one which reads "Expression syntax in function main". I've read your guide on answering students questions, just really hoping you can point me in the right direction with what to look for. I've gone through it many times and I'm sure all the silly mistakes have gone (like missing off ; and spellings). It works fine when it asks the user for the file name of the text file and it recognises if the file is not there so I'm hoping this means that it is opening the file, however after this istead of working out the average word length etc and displaying it on the screen it gives me an 8 letter code that is constant for the file I created to test my programme on.

    I've got about 18 hours before the deadline, any help would be much appreciated,

    Thanks
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    We can't help you with errors of that nature without seeing some code.

    Comment

    • PlainLazy
      New Member
      • Mar 2008
      • 2

      #3
      Ah ok, here is the part I think the error will be in...

      [CODE] /*if the file can be found, starts counting and everything else*/
      else(){

      /*If the first character is a letter, then the word count error block is set to
      count the character as part of a word, if not it is set to count it as not a word.*/

      for(firstCharEr ror; firstCharError= =1; firstCharError+ +){
      if(isalpha(test Char)==1){
      errorBlock=1;
      }
      }

      /*This will repeat until the end of file character is found*/
      while( feof(testChar=( getc(fp)))!=1){

      /*This will be used later in the word count to see if the preceeding character is a space, new line or new page*/
      if(testChar==32 || testChar==10 || testChar==12){
      errorCarry=2;
      }
      else(){
      errorCarry=1;
      }

      switch(isalpha( testChar)) {

      /*If the character is a letter then put it into capitals, count it, then increment the matching letter count array*/
      case 1:
      if(testChar>64 && testChar<91){
      testChar=testCh ar+32;
      }
      ++charCount;
      testChar-=97;
      ++letterCount[testChar];
      break;

      /*If the character is not a letter, it is determined whether it is a space, new line or new page and whether
      it is preceeded by a letter or punctuation using errorBlock. If so then the word count is increased*/
      case 0:
      if((testChar==3 2 || testChar==10 || testChar==12) && errorBlock==1){
      ++wordCount;
      }
      }

      errorBlock=erro rCarry;
      }

      /*After reaching the end of the document, the word count is increased if the last characters were part of a word*/
      if(errorBlock== 1){
      ++wordCount;
      }

      fclose(fp); [CODE]

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        The compiler should tell you what line the error is in...on first glance, I don't see anything there other than an inline assignment in the while loop that might be giving you issues, since assignments have a value. To end CODE tags, you use [/CODE], fyi.

        Comment

        Working...