Calculating Reading Score with a C Program

  • Thread starter Thread starter akieft
  • Start date Start date
  • Tags Tags
    Program Reading
Click For Summary
SUMMARY

The forum discussion revolves around a C program designed to calculate the reading score based on the number of words, vowels, and sentences in a text file named "beatles.txt". The user is utilizing the Quincy 99 compiler but encounters errors, including a "qcc.exe installation error". Key issues identified include the improper use of the fgets function, which only reads one line, and the need for a single loop to count vowels, words, and sentences simultaneously. Recommendations include fixing the compiler installation and restructuring the code to improve functionality.

PREREQUISITES
  • C programming fundamentals
  • Understanding of file I/O in C
  • Knowledge of control structures (loops and conditionals)
  • Familiarity with string manipulation in C
NEXT STEPS
  • Learn about C file handling with fopen and fgets functions
  • Research how to implement a single loop for multiple counting tasks in C
  • Explore debugging techniques in C, including using printf for tracing
  • Study the Flesh Reading Ease Score calculation and its implementation in C
USEFUL FOR

Beginner C programmers, students learning file I/O, and anyone interested in text analysis algorithms.

  • #31
akieft said:
no the installation error is fixed. Basically the program runs, the output is ok1 and then quincy pops up an error saying that this program has quit unexpectedly and you have the option to close, debug, or send error to microsoft. If you click debug its just a bunch of numbers and I have no idea what they mean. I have a feeling it has to do with the while loop but I am unsure how to fix it.

When you see that error, it usually means you have committed a "pointer" error. That means you are trying to use a piece of memory which you think contains data, but which actually "does not exist".

The only place I see in your code where you could have committed such an error is with your FILE *input variable. It is possible, if fopen fails, that it could return NULL. Then when you say fgets(...input) later, fgets will try to read from NULL (bad) and crash.

Try adding the line

perror("fopen");

Right after you say fopen (this will cause fopen's exact error message to be printed, if there is one), or changing your printf right there to

printf("ok %x\n", input); /*if fopen succeeded, this will print a nonzero number, if it failed it will print "ok 0"*/

(If you want to be really fancy you could to an if() test to see whether "input" is equal to 0, and if input is equal to 0 print "Beatles.txt not found!" and politely quit. Your teacher would probably prefer this. But this will not solve the problem that your program doesn't work, it will just make it not work in a more polite way...)

Most compilers come with a "debugger", which when you commit a pointer error they will stop the program in its tracks and show you the source code of the line where the error happened. It is essential you learn to use a debugger someday. Does QCC not come with one?
 
Last edited:
Technology news on Phys.org
  • #32
not that we have been taught no...Our prof has never shown us a debugger to my knowledge neither has our TA
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
Replies
1
Views
2K
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
3
Views
2K
  • · Replies 22 ·
Replies
22
Views
6K