User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 427,988 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,438 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Jun 20th, 2005
Views: 2,155
It's a simple program .Just enter any date in dd/mm/yyyy format.If you enter wrong you will get the message .
c Syntax | 4 stars
  1. # include<stdio.h>
  2. # include<conio.h>
  3. # include<string.h>
  4.  
  5. # include<math.h>
  6. int check_date(char[]);
  7. int converttointeger(char[]);
  8. void main()
  9. { clrscr();
  10. char date[11];
  11. int c;
  12. puts("ENTER ANY DATE : ");
  13. gets(date);
  14. c= check_date(date);
  15. if(c==0)
  16. puts("\nINVALID DATE");
  17. else
  18. puts("VALID DATE");
  19. getch();
  20. }
  21.  
  22. int check_date(char a[])
  23. { int l,d,y,logic = 0;char dd[4],mm[4],yy[5];
  24. l = strlen(a);
  25. if(l!=10)
  26. return 0;
  27.  
  28. else if(a[2] !='/' && a[5] !='/')
  29. return 0;
  30.  
  31. dd[0]=a[0];dd[1]=a[1];dd[2]='\0';
  32. mm[0]=a[3];mm[1]=a[4];mm[2]='\0';
  33. yy[0]=a[6];yy[1]=a[7];yy[2]=a[8];
  34. yy[3]=a[9];yy[4]='\0';
  35. d = converttointeger(dd);
  36. y = converttointeger(yy);
  37.  
  38.  
  39.  
  40. // Case of months having 31 days
  41.  
  42. if(strcmp(mm,"01")==0 || strcmp(mm,"03")==0 || strcmp(mm,"05")==0 || strcmp(mm,"07")==0 || strcmp(mm,"08")==0 || strcmp(mm,"10")==0 || strcmp(mm,"12")==0 )
  43. { if( d>=1 && d<=31)
  44. { logic = 1;
  45. }
  46. }
  47. // Case of Februaury
  48. else if(strcmp(mm,"02")==0)
  49. { if(d>=1 && d<=28)
  50. { logic =1;
  51. }
  52. if(d == 29 && y % 4 == 0)
  53. { logic=1;
  54. }
  55. }
  56. // Case of months having 30 days
  57. else if(strcmp(mm,"04")==0 || strcmp(mm,"06")==0 || strcmp(mm,"09")==0 || strcmp(mm,"11")==0)
  58. {
  59. if(d>=1 && d<=30)
  60. { logic =1;
  61. }
  62. }
  63.  
  64. return logic;
  65. }
  66.  
  67. int converttointeger(char str[])
  68. { int r,p,i,k;
  69. r=0;
  70. k=0;
  71. p = pow(10,(strlen(str)-1));
  72. for(i=0;i<strlen(str);i++)
  73. { k= str[i] - '0';
  74. r += (k*p);
  75. p/=10;
  76. }
  77. return r;
  78. }
  79.  
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 9:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC