Hallo,
ich hab ein Programm geschrieben, dass einen sinus ausrechnet.
Ich möchte es in einem Unterprogramm machen und dann die Struct-variable zurückgeben, das ich dann im Hauptprogramm ausgeben.
Zusätzlich sollen x, y in ein Array gespeichert werden.
Irgendwie hats das was, wenn ich gleich im Unterprogramm ausgebe das versteh ich bzw. da klappts.
Schaut es euch bitte mal an.
[cpp]
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MAXLEN 10
struct punkt_struct
{
float x;
float y;
};
typedef struct punkt_struct punkt;
punkt getpunkte(punkt point[], int len);
//void fndminimum(punkt point[], int len);
punkt getpunkte(punkt point[], int len)
{
double t=0;
for(t=0.0; t<len; t=t+0.1)
{
point[(int)t].x=(float)t;
point[(int)t].y=sin((float)t);
//printf("sin(%f)=%f\n",point[(int)t].x,point[(int)t].y);
}
return(point[MAXLEN]);
}
//void fndminimum(punkt point[], int len)
//{
//
//}
int main()
{
double t=0;
punkt allpoints[MAXLEN];
allpoints[MAXLEN]=getpunkte(allpoints, MAXLEN);
return(0);
}
Wenn ich mit Einzelschritt durchgehe dann kommt es in der 2. Zeile der for()-schleife net mehr weiter.
[/cpp]
MfG
ich hab ein Programm geschrieben, dass einen sinus ausrechnet.
Ich möchte es in einem Unterprogramm machen und dann die Struct-variable zurückgeben, das ich dann im Hauptprogramm ausgeben.
Zusätzlich sollen x, y in ein Array gespeichert werden.
Irgendwie hats das was, wenn ich gleich im Unterprogramm ausgebe das versteh ich bzw. da klappts.
Schaut es euch bitte mal an.
[cpp]
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MAXLEN 10
struct punkt_struct
{
float x;
float y;
};
typedef struct punkt_struct punkt;
punkt getpunkte(punkt point[], int len);
//void fndminimum(punkt point[], int len);
punkt getpunkte(punkt point[], int len)
{
double t=0;
for(t=0.0; t<len; t=t+0.1)
{
point[(int)t].x=(float)t;
point[(int)t].y=sin((float)t);
//printf("sin(%f)=%f\n",point[(int)t].x,point[(int)t].y);
}
return(point[MAXLEN]);
}
//void fndminimum(punkt point[], int len)
//{
//
//}
int main()
{
double t=0;
punkt allpoints[MAXLEN];
allpoints[MAXLEN]=getpunkte(allpoints, MAXLEN);
return(0);
}
Wenn ich mit Einzelschritt durchgehe dann kommt es in der 2. Zeile der for()-schleife net mehr weiter.
[/cpp]
MfG