strftime in C

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main()
{
        char a[10];
        strftime (a,10,"%B"," ");
        puts(a);

        return 0;
}

above code gives 'March' as output. can anyone explain the reason for it. Also how can i use it to write a program which takes a number(1-12) as input and print corresponding month.
Last edited on
You're doing code tags wrong. The code goes inside them, not after them ;P

can anyone explain the reason for it.


You're using it wrong. The 4th parameter should be a pointer to a tm struct. You're giving it a pointer to a C string. It's probably just reading random garbage and interpretting it as 'March'

See this for an example of how to use strftime: http://www.cplusplus.com/reference/clibrary/ctime/strftime/

EDIT:

also, here is the tm struct:

http://www.cplusplus.com/reference/clibrary/ctime/tm/
Last edited on
It's probably just reading random garbage and interpretting it as 'March'

got it.

thanx for the reply and the link.
Topic archived. No new replies allowed.