Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
jobrod
/
Week3Programming2JordanBrodie
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
73fa8c35
authored
Feb 25, 2025
by
jobrod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update uniquewords.c
parent
844156f3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletions
uniquewords.c
uniquewords.c
View file @
73fa8c35
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
...
@@ -17,6 +16,7 @@ typedef struct {
...
@@ -17,6 +16,7 @@ typedef struct {
void
process_file
(
const
char
*
filename
);
void
process_file
(
const
char
*
filename
);
int
count_unique_words
(
char
*
line
,
WordCount
*
word_counts
,
int
*
unique_word_count
);
int
count_unique_words
(
char
*
line
,
WordCount
*
word_counts
,
int
*
unique_word_count
);
int
find_word
(
WordCount
*
word_counts
,
int
unique_word_count
,
const
char
*
word
);
int
find_word
(
WordCount
*
word_counts
,
int
unique_word_count
,
const
char
*
word
);
void
remove_punctuation
(
char
*
line
);
int
main
()
int
main
()
{
{
...
@@ -45,6 +45,7 @@ void process_file(const char *filename)
...
@@ -45,6 +45,7 @@ void process_file(const char *filename)
while
(
fgets
(
line
,
sizeof
(
line
),
file
))
while
(
fgets
(
line
,
sizeof
(
line
),
file
))
{
{
remove_punctuation
(
line
);
count_unique_words
(
line
,
word_counts
,
&
unique_word_count
);
count_unique_words
(
line
,
word_counts
,
&
unique_word_count
);
}
}
...
@@ -53,6 +54,21 @@ void process_file(const char *filename)
...
@@ -53,6 +54,21 @@ void process_file(const char *filename)
printf
(
"There are %d different words in this text.
\n
"
,
unique_word_count
);
printf
(
"There are %d different words in this text.
\n
"
,
unique_word_count
);
}
}
// Function to remove punctuation from a line
void
remove_punctuation
(
char
*
line
)
{
char
*
src
=
line
,
*
dst
=
line
;
while
(
*
src
)
{
if
(
!
ispunct
((
unsigned
char
)
*
src
))
{
*
dst
++
=
*
src
;
}
src
++
;
}
*
dst
=
'\0'
;
}
// Function to count unique words in a line
// Function to count unique words in a line
int
count_unique_words
(
char
*
line
,
WordCount
*
word_counts
,
int
*
unique_word_count
)
int
count_unique_words
(
char
*
line
,
WordCount
*
word_counts
,
int
*
unique_word_count
)
{
{
...
@@ -103,3 +119,4 @@ int find_word(WordCount *word_counts, int unique_word_count, const char *word)
...
@@ -103,3 +119,4 @@ int find_word(WordCount *word_counts, int unique_word_count, const char *word)
}
}
return
-
1
;
return
-
1
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment