Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
string concatenation
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Sean Burke, post: 1704948"] [i][i][i] Anyone who knows how to use strtol doesn't need advice from me. :-) But how many people just pass the argument to atoi() and let any problems manifest themselves further along? I think the method I illustrated has the virtue of being a "pretty good" filter, while also being much more widely applicable than strtol(). Suppose I want to accept an IP address, but I want to ensure that it's not a domain name: if (strspn(argv[i], ".0123456789") != strlen(argv[i])) fprintf(stderr, "Arg \"%s\" must be an numeric IP address.\n", argv[i]); Sure, "...0" would pass this filter, but the chief goal is to reject "foo.bar.com". Yes, I could use inet_addr() instead, but what does inet_addr() do with "9.37.190.192.in-addr.arpa"? Certainly, regcomp/regexec provide a filtering method that can be both precise and very general. But strspn/cspn() provide a useful balance of precision and convenience. -SEan[/i][/i][/i][/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
string concatenation
Top