Aquaaa
Aquaaa

Reputation: 7

How to parse argv in C (between commas)

I have a little problem with my C program. I would like to parse the args in cmdline into tokens. For example, the program will be running like this: ./hello a b , c , ab c d I want to have all letters between commas to be in a variable. So argv[1] would be a b ; argv[2] would be c ; argv[3] ab c d Is there a way to do it? So that I will be able to play with all token between commas.

Thanks!

Upvotes: 0

Views: 86

Answers (1)

dbush
dbush

Reputation: 224427

Use quotes around the arguments. Then they'll be treated separately by the shell and passed in as such.

./hello "a b" "c" "ab c d"

Upvotes: 3

Related Questions