Skip to content

Commit

Permalink
Finish speller and organise files
Browse files Browse the repository at this point in the history
  • Loading branch information
someshkar committed Dec 11, 2019
1 parent 9d6afc8 commit abe1acb
Show file tree
Hide file tree
Showing 93 changed files with 1,078,520 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions pset4/speller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# compiler to use
CC = clang

# flags to pass compiler
CFLAGS = -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow

# name for executable
EXE = speller

# space-separated list of header files
HDRS = dictionary.h

# space-separated list of libraries, if any,
# each of which should be prefixed with -l
LIBS =

# space-separated list of source files
SRCS = speller.c dictionary.c

# automatically generated list of object files
OBJS = $(SRCS:.c=.o)


# default target
$(EXE): $(OBJS) $(HDRS) Makefile
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

# dependencies
$(OBJS): $(HDRS) Makefile

# housekeeping
clean:
rm -f core $(EXE) *.o
29 changes: 29 additions & 0 deletions pset4/speller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Questions

## What is pneumonoultramicroscopicsilicovolcanoconiosis?

"An artificial long word said to mean a lung disease caused by inhaling very fine ash and sand dust."

## According to its man page, what does `getrusage` do?

`getrusage` returns resource usage measures for who.

## Per that same man page, how many members are in a variable of type `struct rusage`?

16

## 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?

We pass `before` and `after` by reference to the function `calculate` because passing large structs by value is slow. Passing by value to `calculate` will go to the stack, which could potentially cause stack overflow.

## Explain as precisely as possible, in a paragraph or more, how `main` goes about reading words from a file. In other words, convince us that you indeed understand how that function's `for` loop works.

The key in the `for` loop is the `int c = fgetc(file); c != EOF; c = fgetc(file)` which reads through the entire text file. Essentially `c` is the letter of the word and the `for` loop goes through each letter of the word while checking for conditions. These conditions are to allow only alphabetical characters and apostrophe and also ignoring words with numbers in them. The `index` is the length of the word and within the conditions, the rest of the alphabetical string is consumed, if it matches the condition. Once this process is done and the condition of the word is not an alpanumeric or a number, then the word is complete. Signaling `word[index] = '\0'` would terminate the word, spell check it and start a new word. The `index` is then reset to 0 to denote a new word.

## 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?

Using `fgetc` is not error prone because you want to check each individual characters for conditions (such as making sure it's alphanumeric, ignore digits, etc.) of the string. `fscanf` would read them and may potentially cause errors.

## Why do you think we declared the parameters for `check` and `load` as `const` (which means "constant")?

These parameters are declared as `const` because we don't want the dictionary or word to be changed during the process of loading the dictionary and checking each word.
Loading

0 comments on commit abe1acb

Please sign in to comment.