Probleme beim speichern eingelesener Werte



  • Hallo,

    ich will eine Funktion schreiben, die einige Werte einliest und eine Überprüfung auf Korrektheit durchführt.

    Sieht so aus:

    int datum(int *jahr, int *monat, int *tag)
    {
    	int istschaltjahr=0;
    
    	printf("Jahr: ");
    	scanf("%i\n", &jahr);
    	if(*jahr<0){printf("Falsche Eingabe."); return 0;}
    
    	printf("Monat: ");
    	scanf("%i\n", &monat);
    	if(*monat<=0 || *monat>12){printf("Falsche Eingabe."); return 0;}
    
    	printf("Tag: ");
    	scanf("%i", &tag);
    	if(*tag<=0 || *tag>31){printf("Falsche Eingabe."); return 0;}
    	if(*monat==2 && *tag>29){printf("Falsche Eingabe."); return 0;}
    

    (nicht vollständig)

    Ich hab beim Ausführen aber das Problem, dass anscheinend die eingelesene Variable (jahr) nicht in jahr gespeichert wird. Auf jeden Fall gehts nach der Eingabe und bestätigen nicht weiter, wo eigtl "Monat:" kommen sollte.
    Mir scheint, als mache ich da irgendwas mit dem Adressoperator und Pointer falsch. Ich versteh nicht so ganz, wie ich die eingelesenen Werte richtig abspeichere.
    Kann mir vllt jemand den Fehler zeigen und erklären, was genau da falsch läuft?

    Vielen Dank schonmal.



  • --Q-- schrieb:

    scanf("%i\n", &jahr);
    

    Da brauchst du keinen Adressoperator, da jahr ja bereits ein Zeiger ist. Gilt für monat und tag natürlich ebenso.



  • Tatsächlich, das funktioniert. Dankeschön!
    Und warum is das so? Ich verstehs ncht so ganz.

    Oh und noch ein Problem.
    Ich hoff das is ok, wenn ich das in diesen Thread mit reinschreib.
    Und zwar meldet mir Emacs folgendes, immer dann, wenn ich <stdlib.h> include:

    make -k 404g_angabe
    cc -g -ansi -pedantic-errors -Waggregate-return -Werror -I../include -c -o 404g_angabe.o 404g_angabe.c
    In file included from /usr/include/i386/_structs.h:38,
    from /usr/include/machine/_structs.h:31,
    from /usr/include/sys/_structs.h:57,
    from /usr/include/sys/signal.h:154,
    from /usr/include/sys/wait.h:116,
    from /usr/include/stdlib.h:65,
    from 404g_angabe.c:20:
    /usr/include/mach/i386/_structs.h:91: error: type of bit-field '__invalid' is a GCC extension
    /usr/include/mach/i386/_structs.h:92: error: type of bit-field '__denorm' is a GCC extension
    /usr/include/mach/i386/_structs.h:93: error: type of bit-field '__zdiv' is a GCC extension
    /usr/include/mach/i386/_structs.h:94: error: type of bit-field '__ovrfl' is a GCC extension
    /usr/include/mach/i386/_structs.h:95: error: type of bit-field '__undfl' is a GCC extension
    /usr/include/mach/i386/_structs.h:96: error: type of bit-field '__precis' is a GCC extension
    /usr/include/mach/i386/_structs.h:97: error: type of bit-field '<anonymous>' is a GCC extension
    /usr/include/mach/i386/_structs.h:98: error: type of bit-field '__pc' is a GCC extension
    /usr/include/mach/i386/_structs.h:104: error: type of bit-field '__rc' is a GCC extension
    /usr/include/mach/i386/_structs.h:111: error: type of bit-field '<anonymous>' is a GCC extension
    /usr/include/mach/i386/_structs.h:112: error: type of bit-field '<anonymous>' is a GCC extension
    /usr/include/mach/i386/_structs.h:149: error: type of bit-field '__invalid' is a GCC extension
    /usr/include/mach/i386/_structs.h:150: error: type of bit-field '__denorm' is a GCC extension
    /usr/include/mach/i386/_structs.h:151: error: type of bit-field '__zdiv' is a GCC extension
    /usr/include/mach/i386/_structs.h:152: error: type of bit-field '__ovrfl' is a GCC extension
    /usr/include/mach/i386/_structs.h:153: error: type of bit-field '__undfl' is a GCC extension
    /usr/include/mach/i386/_structs.h:154: error: type of bit-field '__precis' is a GCC extension
    /usr/include/mach/i386/_structs.h:155: error: type of bit-field '__stkflt' is a GCC extension
    /usr/include/mach/i386/_structs.h:156: error: type of bit-field '__errsumm' is a GCC extension
    /usr/include/mach/i386/_structs.h:157: error: type of bit-field '__c0' is a GCC extension
    /usr/include/mach/i386/_structs.h:158: error: type of bit-field '__c1' is a GCC extension
    /usr/include/mach/i386/_structs.h:159: error: type of bit-field '__c2' is a GCC extension
    /usr/include/mach/i386/_structs.h:160: error: type of bit-field '__tos' is a GCC extension
    /usr/include/mach/i386/_structs.h:161: error: type of bit-field '__c3' is a GCC extension
    /usr/include/mach/i386/_structs.h:162: error: type of bit-field '__busy' is a GCC extension
    make: *** [404g_angabe.o] Error 1
    make: Target `404g_angabe' not remade because of errors.

    Compilation exited abnormally with code 2 at Sat Dec 13 21:40:49

    Daraus werd ich überhaupt nicht schlau, außer dass offensichtlich mit Bibliotheksfunktion nicht stimmt. Aber was und wie behebe ich das?



  • hehe - jahr ist zwar ein Pointer aber wohin zeigt der denn ?
    Das crasht 🙂



  • Versteh ich jetzt nicht 😕

    Egal, viel wichtiger ist das andere Problem. Ich kann nicht kompilieren.
    Ist übrigens ne andere Aufgabe, die erste läuft jetzt korrekt.



  • Hat sich erledigt.


Anmelden zum Antworten