Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: Reading and discarding characters from the input stream
To show: How to read & discard characters
Code:
// Reading and discarding characters from the input stream
// don't forget to put the .h lor!
#include <stdio>
int main()
{
int month1, day1, year1, month2, day2, year2;
printf("Enter a date in the form mm-dd-yy: ");
//pad 0 for two fields and discarding the - characters....
/* scanf("%d%*c%d%*c%d", &month1, &day1, &year1); */
scanf_s("%d%*c%d%*c%d", &month1, &day1, &year1);
printf("month = %02d day = %02d year = %02d\n\n", month1, day1, year1);
printf("Enter a date in the form mm/dd/yy: ");
//pad 0 for two fields and discarding the / characters...
/* scanf_s("%d%*c%d%*c%d", &month2, &day2, &year2); */
scanf_s("%d%*c%d%*c%d", &month2, &day2, &year2);
printf("month = %02d day = %02d year = %02d\n", month2, day2, year2);
return 0;
}
Output:Code:
Enter a date in the form mm-dd-yy: 12-05-2004
month = 12 day = 05 year = 2004
Enter a date in the form mm/dd/yy: 10/07/2000
month = 10 day = 07 year = 2000
Press any key to continue . . .