Skip to content

Commit

Permalink
switched out the strtok
Browse files Browse the repository at this point in the history
  • Loading branch information
thewisepeter committed Apr 29, 2023
1 parent 266b956 commit 46af354
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions get_location.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ char *get_location(char *command)
{
path_copy = _strdup(path);
command_length = _strlen(command);
path_token = strtok(path_copy, ":");
path_token = _strtok(path_copy, ":");
while (path_token != NULL)
{
directory_length = _strlen(path_token);
Expand All @@ -34,7 +34,7 @@ char *get_location(char *command)
else
{
free(file_path);
path_token = strtok(NULL, ":");
path_token = _strtok(NULL, ":");
}
}
free(path_copy);
Expand Down
2 changes: 2 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ int _atoi(char *s);
int has_space(char *input);
int _isletter(int c);
char *_realloc(char *ptr, size_t size);
char *_strtok(char *str, const char *delim);

#endif /* _MAIN__H_ */
4 changes: 2 additions & 2 deletions num_tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ int num_token(char *str, const char *delim)
char *token;
int token_num;

token = strtok(str, delim);
token = _strtok(str, delim);

token_num = 0;
while (token != NULL)
{
token_num++;
token = strtok(NULL, delim);
token = _strtok(NULL, delim);
}
return (token_num);
}
10 changes: 5 additions & 5 deletions parse_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ char **parse_input(char *input, const char *delim, int *num_tokens)
int i;
char **argv;

input_copy = strdup(input);
input_copy = _strdup(input);
if (!input_copy)
error("string duplication error");
*num_tokens = 0;
token = strtok(input_copy, delim);
token = _strtok(input_copy, delim);
while (token)
{
(*num_tokens)++;
token = strtok(NULL, delim);
token = _strtok(NULL, delim);
}

argv = safe_malloc(sizeof(char *) * ((*num_tokens) + 1));
token = strtok(input, delim);
token = _strtok(input, delim);
for (i = 0; token; i++)
{
argv[i] = safe_malloc(sizeof(char) * (strlen(token) + 1));
strcpy(argv[i], token);
token = strtok(NULL, delim);
token = _strtok(NULL, delim);
}
argv[i] = NULL;

Expand Down

0 comments on commit 46af354

Please sign in to comment.