Fehlermeldung(Unbehandlete Ausnahme bei...), Strukturen

Googlehupf

Erfahrenes Mitglied
Hallo,

ich hab ein Programm geschrieben das Komplexe Zahlen addiert, subthariert und multipliziert.
Aber nur tritt einer Fehlermeldung(oder so) auf, wenn ich mit Einzelschritt durchgehe.

Das Programm besteht aus einem H-File und 2 C-Files.

Header-File:

C++:
struct complex_struct
{
  double real;
  double imag;
};
typedef struct complex_struct complex;


complex c_add(complex a, complex b);


complex c_sub(complex a, complex b);

complex c_multi(complex a, complex b);



void c_print_add(complex a);

void c_print_sub(complex a);


void c_print_multi(complex a);

1. C-File(Unterprogramme):

C++:
#include "compl.h"
#include <stdio.h>

complex c_add(complex a, complex b)
{
  complex result;
  result.real = a.real + b.real;
  result.imag = a.imag + b.imag;
  return result;
}

void c_print_add(complex a)
{
  printf("%lf + j%lf",a.real,a.imag);
}


complex c_sub(complex a, complex b)
{
  complex result;
	result.real = a.real - b.real;
	result.imag = a.imag - b.imag;
	return result;
}

void c_print_sub(complex a)
{
  printf("%lf - j%lf",a.real,a.imag);
}

complex c_multi(complex a, complex b)
{
  complex result;

  result.real = (a.real*b.real) + ((-1)*(a.imag*b.imag));
  result.imag = (a.imag*b.real) + (b.imag*a.real);
}

void c_print_multi(complex a)
{
  printf("%lf j%lf",a.real,a.imag);
}

2.C-file(Hauptprogramm):

C++:
#include <stdio.h>
#include "compl.h"

void main()
{
  complex c1 = {4.0,5.9};
  complex c2;
  complex c3;

  c2.real=7;
  c2.imag=0.1;
  c3 = c_add(c1,c2);
  c_print_add(c1);
  printf(" + ");
  c_print_add(c2);
  printf(" = ");
  c_print_add(c3);
  printf("\n");

  c2.real=7;
  c2.imag=0.1;
  c3 = c_sub(c1,c2);
  c_print_sub(c1);
  printf(" - ");
  c_print_sub(c2);
  printf(" = ");
  c_print_sub(c3);
  printf("\n");

  c2.real=7;
  c2.imag=0.1;
  c3 = c_multi(c1,c2);//hier kommt die Fehlermeldung(siehe pic)
  c_print_multi(c1);
  printf(" * ");
  c_print_multi(c2);
  printf(" = ");
  c_print_multi(c3);
  printf("\n");
}

Was könnte es da haben?

Danke im voraus!

mfg googlehupf
 

Anhänge

  • error.png
    error.png
    11,6 KB · Aufrufe: 6
Hallo,

du hast in c_multi vergessen, einen Wert zurückzugeben. Hat dich dein Compiler etwa nicht darauf hingewiesen!?

\edit: %lf gibt es bei printf nicht, es sollte einfach nur %f heißen.

Grüße,
Matthias
 
Ok, stimmt danke :)

Ich hab ein Problem mit der komplexen Division, ich weis nicht wie ich die schreiben könnte..., weil wenn wir z.B haben 2+5,9j/7+0,5j dann müsste man konjungiert komplex erweitern und das ist irgendwie zu aufwendig zu programmieren finde ich.. gibts da keine einfachere Lösung?
 
Ich hab ein Problem mit der komplexen Division, ich weis nicht wie ich die schreiben könnte..., weil wenn wir z.B haben 2+5,9j/7+0,5j dann müsste man konjungiert komplex erweitern und das ist irgendwie zu aufwendig zu programmieren finde ich.. gibts da keine einfachere Lösung?
Was ist denn daran zu aufwändig? Die Multiplikation hast du doch auch geschafft. Mehr musst du für die Division auch nicht beherrschen.

Grüße,
Matthias
 
Zurück