0

I can't really figure out the correct answers for questions 3, 5 and 6 in questions.txt for problem set 5 (Mispellings).

3. Why do you think we pass before and after by reference (instead of by value) to calculate, even though we’re not changing their contents?

5. Why do you think we used fgetc to read each word’s characters one at a time rather than use fscanf with a format string like "%s" to read whole words at a time? Put another way, what problems might arise by relying on fscanf alone?

6. Why do you think we declared the parameters for check and load as const?

Any ideas?

3
  1. Why do you think we pass before and after by reference (instead of by value) to calculate, even though we're not changing their contents?

Consider the type of before and after and what are the differences between passing a variable by reference and by value. Specifically what changes in memory allocation.

  1. Why do you think we used fgetc to read each word's characters one at a time rather than use fscanf with a format string like "%s" to read whole words at a time? Put another way, what problems might arise by relying on fscanf alone?

In a terminal use man fscanf and read it through. Also consider what changes in allocating memory for each function's readings.

  1. Why do you think we declared the parameters for check and load as const?

What is the main reason we use constants instead of variables? What is their main difference?


I know my answer is vague but it is intentionally so. You should watch all the videos of the and get a better understanding of the subject. Also a lot of googling is very welcome by the course.

2
  • Well, for question 3, I can't think of any other reasons other than to save memory and time. Question 5, I know it's vulnerable to buffer overflow, but still I don't see any other problems, because the words will never be larger than 45 anyway (speller.c controls it). Question 6, to ensure strings can't be modified during execution? But users don't have control over them at that time anyway! Maybe some programming etiquette? Jul 16 '15 at 13:52
  • Q3 correct. Q5 correct + you don't know that your program will be run with this dictionary every time. Q6 correct + the users might not change them but YOU might change them somewhere in your program. If the instructors make sure that they are constants they know you couldn't possibly change them.
    – ChrisG
    Jul 16 '15 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .