Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS283
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrew To
CS283
Commits
8e62aa53
Commit
8e62aa53
authored
5 months ago
by
Andrew To
Browse files
Options
Downloads
Patches
Plain Diff
Hw2: small fix
parent
f4f730e3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.DS_Store
+0
-0
0 additions, 0 deletions
.DS_Store
Hw2/stringfun
+0
-0
0 additions, 0 deletions
Hw2/stringfun
Hw2/stringfun.c
+12
-10
12 additions, 10 deletions
Hw2/stringfun.c
with
12 additions
and
10 deletions
.DS_Store
+
0
−
0
View file @
8e62aa53
No preview for this file type
This diff is collapsed.
Click to expand it.
Hw2/stringfun
+
0
−
0
View file @
8e62aa53
No preview for this file type
This diff is collapsed.
Click to expand it.
Hw2/stringfun.c
+
12
−
10
View file @
8e62aa53
...
...
@@ -21,7 +21,7 @@ int setup_buff(char *buff, char *user_str, int len){
bool
isSpace
=
false
;
int
count
=
0
;
while
(
*
user_str
!=
'\0'
&&
count
<
BUFFER_SZ
-
1
)
{
// stop when reaching the end-of-buffer
while
(
*
user_str
!=
'\0'
&&
count
<
BUFFER_SZ
)
{
// stop when reaching the end-of-buffer
if
(
*
user_str
!=
'\t'
){
if
(
*
user_str
!=
' '
||
isSpace
==
false
)
{
*
buff
=
*
user_str
;
...
...
@@ -42,7 +42,7 @@ int setup_buff(char *buff, char *user_str, int len){
}
}
int
ret
=
count
;
if
(
count
>
len
){
if
(
count
>
=
BUFFER_SZ
){
return
-
1
;
}
while
(
count
<=
len
){
...
...
@@ -51,7 +51,7 @@ int setup_buff(char *buff, char *user_str, int len){
count
++
;
}
return
ret
;
//for now just so the code compiles.
return
ret
;
}
void
print_buff
(
char
*
buff
,
int
len
){
...
...
@@ -76,6 +76,11 @@ int count_words(char *buff, int len, int str_len){
if
(
str_len
==
0
){
return
0
;
}
if
(
str_len
<
0
){
return
-
1
;
}
int
words
=
1
;
for
(
int
i
=
0
;
i
<
str_len
;
i
++
){
if
(
*
buff
==
' '
){
...
...
@@ -137,7 +142,6 @@ void word_print(char *buff, int len, int str_len){
printf
(
" (%d)
\n
"
,
track
);
}
// void replace(char *buff, *new_buff)
int
main
(
int
argc
,
char
*
argv
[]){
...
...
@@ -191,7 +195,7 @@ int main(int argc, char *argv[]){
buff
=
(
char
*
)
malloc
(
BUFFER_SZ
);
user_str_len
=
setup_buff
(
buff
,
input_string
,
BUFFER_SZ
);
//see todos
if
(
user_str_len
<
0
){
printf
(
"Error setting up buffer, error = %d"
,
user_str_len
);
printf
(
"Error setting up buffer, error = %d
\n
"
,
user_str_len
);
exit
(
2
);
}
...
...
@@ -219,11 +223,9 @@ int main(int argc, char *argv[]){
printf
(
"Need 3 arguments: sample string and 2 other strings
\n
"
);
exit
(
1
);
}
else
{
// buff= (char*)malloc(BUFFER_SZ);
// old_string = argv[3];
// old_str_len = setup_buff()
// new_string = argv[4];
// new_str_len = setup_buff(buff, new_string, BUFFER_SZ);
// char *old_string = argv[3];
// char *new_string = argv[4];
printf
(
"Not Implemented
\n
"
);
break
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment