please help ... to convert date to string

This is a discussion on please help ... to convert date to string within the C Programming forums, part of the General Programming Boards category; Hi, Can you please help me to solve this problem. When i entered: 2 6 the will able to generate ...

  1. #1
    mel
    mel is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    1

    Question please help ... to convert date to string

    Hi,

    Can you please help me to solve this problem.
    When i entered: 2 6
    the will able to generate second of June. But when i tried to execute, there is no response from the program.
    can you please advise on when i wanted to add 3 more days to 2 above and able to generate fifth of June.

    Please help



    2 (day) 6(month) to string Second of June. So far, i am able to convert the following Option 1 and option 2.

    This is the code:

    #include <stdio.h>

    main(){
    char *day[] ={"First","Second","Third","Fourth","Fifth","Sixth ","Seventh",
    "Eighth","Ninth","Tenth","Eleventh","Twelfth","Thi rteenth",
    "Fourteenth","Fifteenth","Sixteenth","Seventeenth" ,
    "Eighteenth","Nineteenth","Twentienth","Twenty-First",
    "Twenty-Second","Twenty-Third","Twenty-Fourth","Twenty-Fifth",
    "Twenty-Sixth","Twenty-Seventh","Twenty-Eighth","Twenty-Ninth",
    "Thirtieth","Thirty-First"};

    char *month[] ={"January","February","March","April","May",
    "June","July","August","September","October",
    "November","December"};

    int choice;
    int dayNum,monthNum,date;


    clrscr();

    do{
    printf("\nMain Menu");
    printf("\n1. Convert Day Integer to Date String");
    printf("\n2. Convert Month Integer to Month String");
    printf("\n3. Convert Date Integer to Date String");


    printf("\n\nEnter Choice:");
    scanf("%d",&choice);} while((choice < 1) || ( choice >3));

    switch(choice){
    case 1 : do{
    printf("\nEnter Day Integer:");
    scanf("%d",&dayNum);
    } while ((dayNum<1) ||(dayNum>31));

    dayNum--;
    printf("\n%s",*(day+dayNum));
    break;

    case 2 : do{
    printf("\nEnter Month Integer:");
    scanf("%d",&monthNum);
    } while ((monthNum<1) || (monthNum>12));
    monthNum--;
    printf("\n%s",*(month+monthNum));

    break;

    case 3 : do{
    printf("Enter Date Integer(Day followed by Month):");
    scanf("%d,%d",&dayNum,&monthNum);
    }while (((dayNum <1) || (dayNum>31)) && ((monthNum<1) || (monthNum>12)));
    dayNum--;
    monthNum--;
    printf("\n%s %s",*(day+dayNum),*(month+monthNum));
    break;
    break;


    default: printf("Invalid selection");
    }
    getch();
    return;
    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Minor errors:

    No return value on main. Should be int main()
    The return on the last line should return a value, preferably 0.
    You have a "double-break" in your switch/case statement.

    Major errors:

    On this line:
    scanf("%d,%d",&dayNum,&monthNum);

    Remove the , (comma) inside scanf.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to convert string into LPCWSTR
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 07:02 AM
  2. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  3. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM
  4. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 10:37 PM
  5. How do i convert a string to a character array?
    By Susan in forum C++ Programming
    Replies: 8
    Last Post: 01-01-2002, 02:31 PM

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