Skip to content

Commit

Permalink
append the nul terminator AGAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
Guitarbum722 committed Feb 10, 2019
1 parent 9ea00a9 commit 129f730
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
int
main()
{
// char *input = "First,\"Middle, Name\",Last";
char *input = "\"Fir,st\",Middle,\"Phone,(home)\",Last";
// char *input = "\"Fir, ()st\",Middle,\"Phone , (home)\",Last";
char *input = "First|Middle|\"Phone | (home)\"|Last";

char sep = ',';
char sep = '|';
char qual = '"';
char *field;

while ((field = strqsep(&input, sep, qual)) != NULL) {
printf("field: %s\n", field);
printf("field: |%s\n", field);
}
free(field);
return 0;
Expand Down
3 changes: 2 additions & 1 deletion qual.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define FALSE 0;

char *
strqsep(char **strp, char sep, char qual)
strqsep(char **strp, const char sep, const char qual)
{
char *field, *start;
int in_quotes = FALSE;
Expand Down Expand Up @@ -38,6 +38,7 @@ strqsep(char **strp, char sep, char qual)

field = (char*) malloc(sizeof(char) * (count + 1)); // make room for NUL terminator
strncpy(field, start, count);
field[count] = '\0';

return field;
}

0 comments on commit 129f730

Please sign in to comment.