Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
kjc015
CSCI206-S21-62
Commits
137fe041
Commit
137fe041
authored
Mar 07, 2021
by
kjc015
Browse files
Lab Complete
parent
b0667bc1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Labs/Lab04/Makefile
View file @
137fe041
...
...
@@ -6,3 +6,5 @@ head2: head2.o fileio.o
$(CC)
$(CFLAGS)
head2.o fileio.o
-o
head2
head3
:
head3.o fileio.o
$(CC)
$(CFLAS)
head3.o fileio.o
-o
head3
string_tokens
:
string_tokens.o
$(CC)
$(CFLAS)
string_tokens.o
-o
string_tokens
Labs/Lab04/string_tokens.c
0 → 100644
View file @
137fe041
/* Kyle Chrysler
* Tuesday 1:20
* lab 04 - string_tokens.c
* compile with: string_tokens
* notes: none
*/
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
// reimplemented from man strtok
int
main
(
int
argc
,
char
*
argv
[])
{
char
*
token
,
*
subtoken
;
// saveptrs store the state for strtok
char
*
saveptr1
,
*
saveptr2
;
int
token_num
=
1
;
if
(
argc
!=
4
)
{
fprintf
(
stderr
,
"Usage: %s string delim subdelim
\n
"
,
argv
[
0
]);
exit
(
EXIT_FAILURE
);
}
// initialize tokenization with argv[1] as str
token
=
strtok_r
(
argv
[
1
],
argv
[
2
],
&
saveptr1
);
while
(
token
!=
NULL
){
// while we have a token, first print it
printf
(
"token %d: %s
\n
"
,
token_num
,
token
);
// then begin extracting subtokens from token
subtoken
=
strtok_r
(
token
,
argv
[
3
],
&
saveptr2
);
while
(
subtoken
!=
NULL
){
// print the subtoken
printf
(
" subtoken --> %s
\n
"
,
subtoken
);
// try to get next subtoken, using saveptr
subtoken
=
strtok_r
(
NULL
,
argv
[
3
],
&
saveptr2
);
}
// try to get next token, using saveptr
token
=
strtok_r
(
NULL
,
argv
[
2
],
&
saveptr1
);
token_num
++
;
}
exit
(
EXIT_SUCCESS
);
}
Write
Preview
Supports
Markdown
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