int day to date string?

This is a discussion on int day to date string? within the C Programming forums, part of the General Programming Boards category; hi. again.. . need some help here how do u actually convert day integer to date string? do i have ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    7

    int day to date string?

    hi. again.. . need some help here

    how do u actually convert day integer to date string?
    do i have to code it 1 by 1... like

    if ( day == 1)
    printf("first");

    eg:

    Enter Day Integer : 3
    Third // <-- result show


    thanks

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Yes, unfortunately!

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    If you want the day of the week, you could to this:
    Code:
       char *weekday[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    
       printf("Today is %s\n",weekday[day]);
    However, it sounds like you want the day of the month.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    7
    aawww..

    i was supposed to program the day and month

    eg.
    enter day : 1
    enter month : 5
    result: First of May

    i have to code from 1 to 31 for day and 12 for month?

    no other way round?

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I would just make two arrays, one for the list of months, and one for the list of days.
    Code:
       char *months[12] = {"Jan","Feb",...};
       char *days[31] = {"first","second","third","fourth","fifth",
          "sixth","seventh","eighth","nighth",...};
    .
    .
       printf("Today is %s of %s\n",days[day],months[mon]);
    Unfortunately, you need an array of 31 day strings. There's not really a pattern where you could break it into two parts, until you get to twenties.

  6. #6
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    See help on strftime()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-13-2007, 09:55 AM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 01:05 PM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 10:16 PM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 05:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21