Hi to everyone,
I'm trying to do my first steps in C-programming the Mega 65 wilt the LLVM-MOS compiler/linker. I'm struggling with the scan-function. The following code will compile without any errors, but when I let it run on the XMega65-Emulator, I'm waiting for my machine, thus I have to use the emulator, than it crashes with the following screen output:
Any ideas or hints regarding this issue? Problem of the scanf implementation or of the emulator?
C
- #include <stdio.h>
- #include <mega65.h>
- int main(void)
- {
- uint16_t day = 2;
- uint16_t month = 6;
- uint16_t year = 2024;
- uint16_t day_of_year;
- uint8_t ii;
- // Abfrage des Datums vom Benutzer
- printf("DATE (D M Y): ");
- scanf("%d %d %d", &day, &month, &year);
- printf("DAY: %d\n", day);
- printf("MONTH: %d\n", month);
- printf("YEAR: %d\n", year);
- // Initialisierung der Variablen für den Tag des Jahres und den Tag des Monats
- day_of_year = day;
- // Berechnung des Tages des Jahres durch Addition der Tage aller vorhergehenden Monate
- for (ii = 1; ii < month; ii++)
- {
- if (ii == 2)
- {
- // Berücksichtigung von Schaltjahren für den Februar
- if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
- {
- day_of_year += 29;
- }
- else
- {
- day_of_year += 28;
- }
- }
- else if (ii == 4 || ii == 6 || ii == 9 || ii == 11)
- {
- // Monate mit 30 Tagen
- day_of_year += 30;
- }
- else
- {
- // Monate mit 31 Tagen
- day_of_year += 31;
- }
- }
- // Ausgabe des Tages des Jahres
- printf("THE DATE IS THE %d. DAY OF YEAR %d.\n", day_of_year, year);
- VICIV.screencol = COLOR_BUBBLEGUM;
- while (1)
- {
- VICIV.bordercol++;
- }
- return 0;
- }
The bad guy is obviously the scanf-function. After commenting it out the code is producing the expected behavior.