C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-12-2002, 08:35 AM   #1
mel
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;
}
mel is offline   Reply With Quote
Old 06-12-2002, 10:26 AM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,122
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.
Magos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 01:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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