Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Quick 'n' Dirty CSV Parser
- // Jesse Costales
- // Aug 2021
- // rjcostales@gmail.com
- //
- // Use freely at own risk.
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int main(int argc, char *argv[])
- {
- char buffer[1024];
- char *token, *quote, *comma;;
- while (fgets(buffer, 1024, stdin)) {
- token = buffer;
- while (*token) {
- // remove whitespace
- while (isspace(*token))
- token++;
- // check for quoted token
- if (*token == '"') {
- quote = strchr(token + 1, '"');
- comma = strchr(quote, ',');
- } else
- comma = strchr(token, ',');
- // find comma and print
- if (comma) {
- *comma = '\0';
- printf("%s\t", token);
- token = comma + 1;
- } else {
- printf("%s", token);
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement