简体   繁体   中英

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 ab, c, ab c d I want to have all letters between commas to be in a variable. So argv[1] would be ab ; 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!

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM