fork download
  1. #include <stdio.h>
  2.  
  3. int isValid(int dd, int mm, int yy);
  4.  
  5. int main()
  6. {
  7. printf("Enter a date in dd/mm/yyyy format: ");
  8. int dd, mm, yy;
  9. scanf("%d/%d/%d", &dd, &mm, &yy);
  10. if (isValid(dd, mm, yy))
  11. printf("The date is valid.\n");
  12. else
  13. printf("The date is invalid.\n");
  14.  
  15. return 0;
  16. }
  17.  
  18. int isValid(int dd, int mm, int yy)
  19. {
  20. //int leapYear;
  21. if (yy <= 0 || mm <= 0 || mm > 12 || dd <= 0)
  22. return 0;
  23. switch(mm)
  24. {
  25. case 1: case 3: case 5: case 7: case 8: case 10: case 12:
  26. int k = 5;
  27. return dd <= 31;
  28. case 4: case 6: case 9: case 11:
  29. return dd <= 30;
  30. default:
  31. printf("Here");
  32. int a = 1;
  33. printf("%d", a);
  34. // int leapYear = yy % 400 == 0 || (yy % 4 == 0 && yy % 100 != 0);
  35. // return dd <= 28 || (leapYear && dd <= 29);
  36. }
  37. return 1; //Control never reaches here
  38. }
  39.  
Compilation error #stdin compilation error #stdout 0s 4288KB
stdin
21/1/2000
compilation info
prog.c: In function ‘isValid’:
prog.c:26:4: error: a label can only be part of a statement and a declaration is not a statement
    int k = 5;
    ^~~
prog.c:26:8: warning: unused variable ‘k’ [-Wunused-variable]
    int k = 5;
        ^
prog.c: In function ‘main’:
prog.c:9:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d/%d/%d", &dd, &mm, &yy);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty