strptime() in linux

W

Wavelet

want to parse the user inputed date format with strptime()
function in Linux.
For example,"12,17:30:20" will be explained as day 12, hour 17 etc.
And I want to get the exact day. I used the following code and it
works well in Solaris,but Segmentation fault in Linux.

Could someone help me out?


=============================================
#define _XOPEN_SOURCE /* glibc2 needs this */
#include <stdio.h>
#include <time.h>


int main() {


struct tm tm;
char buf[255];


strptime("12,17:30:20", "%d", &tm);
printf("ok here\n");
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
puts(buf);
return 0;
 
F

Flash Gordon

Wavelet said:
want to parse the user inputed date format with strptime()
function in Linux.
For example,"12,17:30:20" will be explained as day 12, hour 17 etc.
And I want to get the exact day. I used the following code and it
works well in Solaris,but Segmentation fault in Linux.

Could someone help me out?

<snip>

I'm sure someone can, but not here, since strptime is not part of C but
a POSIX extension. Try comp.unix.programmer
 
R

Richard

Wavelet said:
want to parse the user inputed date format with strptime()
function in Linux.
For example,"12,17:30:20" will be explained as day 12, hour 17 etc.
And I want to get the exact day. I used the following code and it
works well in Solaris,but Segmentation fault in Linux.

Could someone help me out?


=============================================
#define _XOPEN_SOURCE /* glibc2 needs this */
#include <stdio.h>
#include <time.h>


int main() {


struct tm tm;
char buf[255];


strptime("12,17:30:20", "%d", &tm);
printf("ok here\n");
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
puts(buf);
return 0;

At a guess you simply haven't fulfilled the requirements for the C
function strptime format parameter.

But its impossible to know since you dont tell anyone where the problem
was.

Did you step through the program using gdb or similar to detect the
point of seg fault? Do that and all will become clear.
 
K

Kurt Weber

Flash said:
<snip>

I'm sure someone can, but not here, since strptime is not part of C but
a POSIX extension. Try comp.unix.programmer

Oh, don't be a dick.

You clearly know what he's talking about; the least you can do is help him
and then politely suggest that in the future he direct questions regarding
programming with anything except the standard library to a more appropriate
newsgroup.

Grow up.
 
R

Richard

Kurt Weber said:
Oh, don't be a dick.

You clearly know what he's talking about; the least you can do is help him
and then politely suggest that in the future he direct questions regarding
programming with anything except the standard library to a more appropriate
newsgroup.

Grow up.

I was disappointed, after a recent on site project away, to come back &
to see the same people posting the same high & mighty rebuttals in this
NG. A lot of them ONLY post "don't do that" posts. As a help/discussion
group c.l.c is fairly unique in this respect: other language groups have
no where near the same level of childish oneupsmanship being displayed.
 
F

Flash Gordon

Kurt said:
Oh, don't be a dick.

You clearly know what he's talking about;

I checked the Linux documentation sufficiently to find that it was a
POSIX function, I did not bother to read the rest of the man page and I
have never used the function myself.
> the least you can do is help him
and then politely suggest that in the future he direct questions regarding
programming with anything except the standard library to a more appropriate
newsgroup.

Grow up.

If I was being unhelpful I would not have bothered to check if it was a
POSIX function and would not have told the OP where to get help. As it
is I didn't bother to read enough of the documentation to solve the OPs
problem. I'm sure if I wanted to put in a little more effort I could
solve the OPs problem, but why should I when the OP did not put in the
effort to find the right group to ask?
 
K

Keith Thompson

Kurt Weber said:
Oh, don't be a dick.

You clearly know what he's talking about; the least you can do is help him
and then politely suggest that in the future he direct questions regarding
programming with anything except the standard library to a more appropriate
newsgroup.

Grow up.

Meanwhile, the OP has re-posted his question to comp.unix.programmer
and gotten what appears to be a correct answer, which is the whole
point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top