Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > strptime and optional parameters

Reply
Thread Tools

strptime and optional parameters

 
 
mathieu
Guest
Posts: n/a
 
      02-11-2011
Hi,

I am trying to use strptime to read a time formated using format: "%Y
%m%d%H%M%S"
However in my case only %Y is really compulsory. Is there a way to
specify a parameter is not compulsory ?
For instance my input could simply be: "%Y%m%d" or even "%Y%m" (this
has to be left to right)

Thanks
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-11-2011
mathieu <(E-Mail Removed)> writes:

> I am trying to use strptime


strptime is not a standard C function though it is in POSIX.

> to read a time formated using format: "%Y
> %m%d%H%M%S"


That would be ambiguous. It's usually better to have some punctuation
in the format.

> However in my case only %Y is really compulsory. Is there a way to
> specify a parameter is not compulsory ?
> For instance my input could simply be: "%Y%m%d" or even "%Y%m" (this
> has to be left to right)


I think the best solution is to use the standard C function sscanf
because it can tell you how many inputs "matched". This would be more
fussy were it not for the fact that you are using only numeric fields.

sscanf allows you to match fixed-width fields which may be what you
intended with your punctuation-free format.

How you organise things depends on whether there is single obvious
default value for missing fields, or whether you need to set these in
some what that depends on the number of fields found. Also, you may or
may not want to validate some of or all of the input. Given all these
options, I'm reluctant to offer a code fragment.

--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem using the strptime function on HPUXThe strptime function works just kongkolvyu C Programming 4 01-04-2006 11:03 PM
SQLCommand with Optional Parameters? Hanover ASP .Net 1 09-28-2005 08:36 PM
WebMethod and WSDL with optional parameters PMCG ASP .Net Web Services 1 03-02-2004 01:29 PM
Q: How can I pass UDTs into optional parameters in VB 6.0 ? Ramesh MCSD 3 10-22-2003 06:22 PM
Optional parameters in a VB.net function Do ASP .Net 1 10-16-2003 11:50 AM



Advertisments