he variable 'a' is being used without being initialized.



  • Hallo leute ich finde einfach den fehler bei meinem Programm nicht

    #include<stdio.h>
    #include<string.h>
    
    struct komplex
    {
    int imag;
    int real;
    };
    
    void addition(struct komplex*,struct komplex*,struct komplex*);
    
    int main (void)
    
    {
    	struct komplex a;
    	struct komplex b;
    	struct komplex c;
    	int x;
    
    	printf("Geben sie 2 Imaginär zahlen ein");
    	scanf("%i",a.imag);
    	scanf("%i",b.imag);
    	printf("Geben sie 2 real zahlen ein");
    	scanf("%i",a.real);
    	scanf("%i",b.real);
    
    	switch(x)
    	{
    	case 1:
    		addition(&a,&b,&c);
    		break;
    
    	case 2:
    
    		break;
    	}
    	getchar();
    	return(1);
    }
    
    void addition(struct komplex* a,struct komplex* b,struct komplex* c)
    {
    	c->imag=a->imag+b->imag;
    	getchar();
    }
    


  • Du hast den Adressoperator bei deinen ganzen scanf vergessen. Desweiteren ist der Formatspezifizierer für int afaik %d. => Formatchecking bei deinem Compiler aufdrehen

    scanf("%d", &a.imag);
    


  • super Dankeschön 😃

    hast du evt ne gute Seite wo das mit dem struct und an Funktionen übergeben gut erklärt ist ?

    da hab ich noch so meine probleme mit

    vg



  • phil.drossel schrieb:

    hast du evt ne gute Seite wo das mit dem struct und an Funktionen übergeben gut erklärt ist ?
    da hab ich noch so meine probleme mit

    in jedem anfängerbuch sollte das erklärt werden



  • phil.drossel schrieb:

    hast du evt ne gute Seite wo das mit dem struct und an Funktionen übergeben gut erklärt ist ?

    Da hattest du doch keine Probleme.

    314159265358979 schrieb:

    Desweiteren ist der Formatspezifizierer für int afaik %d. => Formatchecking bei deinem Compiler aufdrehen

    Nein. Der Specifier für Dezimal-Integer ist %d.
    Für allgemeine Integer ist %i richtig. Der erkennt dann Zahlen mit führenden Nullen als Oktalzahlen und mit 0x als Hexadezimalzahlen. 😉


Anmelden zum Antworten