Seite 1 von 1

Fehlermeldungen

Verfasst: Do Jun 11, 2015 12:38 pm
von Bumblebe3
Und nochmal habe ich einige Fragen an euch!

Habe folgenden Code:

Code: Alles auswählen

#include <stdio.h>


int scheitelhoehe(struct parabel p, double *y)
{

	// p(x) = a*x^2 + b*x + c

	int rc = 0;
	
	if ((p.a)==0)
    {
                 return rc = 1;
                 }
                 else
                 { 
                     *y = p.c - ((p.b*p.b) / (4*p.a));
                     return rc;
                     }
}


void sort_parabeln(struct parabel *p, int n)
{

	int i, j;
	double y1, y2;
	struct parabel x;
	
	for (i = 0; i < n - 1; i++){
		if (scheitelhoehe(p[i+1], &y2)==0){
			if(scheitelhoehe(p[i], &y1)==1){
				x = p[i+1];
				p[i+1] = p[i];
				p[i] = x;
				i = 0;
			}else{
				if(y2 < y1){
					x = p[i+1];
					p[i+1] = p[i];
					p[i] = x;
					i = 0;
				}
			}
		}
	}
}

int main() {

	struct parabel p[] = {

		{1,2,3}, // 2

		{2,5,-19}, //-22

		{0,0,0},

		{-1,0,0} // 0
	};

	double y;

	printf("Index 1 ist eine echte Parabel: %d\n", scheitelhoehe(p[0], &y) == 0);

	sort_parabeln(p, sizeof(p) / sizeof(struct parabel));
	return 0;

}
Wenn ich diesen aber kompilieren möchte, meckert mein Compiler rum und spuckt mir einige Fehlermeldungen aus :shock:

4 [Warning] "struct parabel" declared inside parameter list
4 [Warning] its scope is only this definition or declaration, which is probably not what you want
5 parameter `p' has incomplete type
23 [Warning] "struct parabel" declared inside parameter list
28 storage size of 'x' isn't known
31 invalid use of undefined type `struct parabel'
31 invalid use of undefined type `struct parabel'
31 pointer to incomplete type
32 invalid use of undefined type `struct parabel'
32 dereferencing pointer to incomplete type
33 invalid use of undefined type `struct parabel'
33 invalid use of undefined type `struct parabel'
33 dereferencing pointer to incomplete type
34 invalid use of undefined type `struct parabel'
34 invalid use of undefined type `struct parabel'
34 dereferencing pointer to incomplete type
34 invalid use of undefined type `struct parabel'
34 dereferencing pointer to incomplete type
35 invalid use of undefined type `struct parabel'
35 dereferencing pointer to incomplete type
39 invalid use of undefined type `struct parabel'
39 invalid use of undefined type `struct parabel'
39 dereferencing pointer to incomplete type
40 invalid use of undefined type `struct parabel'
40 invalid use of undefined type `struct parabel'
40 dereferencing pointer to incomplete type
40 invalid use of undefined type `struct parabel'
40 dereferencing pointer to incomplete type
41 invalid use of undefined type `struct parabel'
41 dereferencing pointer to incomplete type
51 elements of array `p' have incomplete type
53 [Warning] excess elements in struct initializer
53 [Warning] (near initialization for `p[0]')
53 [Warning] excess elements in struct initializer
53 [Warning] (near initialization for `p[0]')
53 [Warning] excess elements in struct initializer
53 [Warning] (near initialization for `p[0]')
55 [Warning] excess elements in struct initializer
55 [Warning] (near initialization for `p[1]')
55 [Warning] excess elements in struct initializer
55 [Warning] (near initialization for `p[1]')
55 [Warning] excess elements in struct initializer
55 [Warning] (near initialization for `p[1]')
57 [Warning] excess elements in struct initializer
57 [Warning] (near initialization for `p[2]')
57 [Warning] excess elements in struct initializer
57 [Warning] (near initialization for `p[2]')
57 [Warning] excess elements in struct initializer
57 [Warning] (near initialization for `p[2]')
59 [Warning] excess elements in struct initializer
59 [Warning] (near initialization for `p[3]')
59 [Warning] excess elements in struct initializer
59 [Warning] (near initialization for `p[3]')
59 [Warning] excess elements in struct initializer
59 [Warning] (near initialization for `p[3]')
51 array size missing in 'p'
51 storage size of 'p' isn't known
66 invalid application of `sizeof' to incomplete type `parabel'
66 [Warning] division by zero


Es sind ja ziemlich viele gleiche Meldungen dabei aber wie löse ich die?

Re: Fehlermeldungen

Verfasst: Do Jun 11, 2015 1:33 pm
von Bumblebe3
Ok ich habs. Oh du meine Güte warum hab ich das nur gepostet *schämundwegrenn*

Ich hab die Parabel vergessen zu deklarieren!

Re: Fehlermeldungen

Verfasst: So Jun 14, 2015 12:04 pm
von Froschmeister
Bumblebe3 hat geschrieben:Ok ich habs. Oh du meine Güte warum hab ich das nur gepostet *schämundwegrenn*

Ich hab die Parabel vergessen zu deklarieren!
Also quasie so:

Code: Alles auswählen

#include <stdio.h>



struct parabel{
	int a;
	int b;
	int c;
};


int scheitelhoehe(struct parabel p, double *y)
{

   // p(x) = a*x^2 + b*x + c

   int rc = 0;

   if ((p.a)==0)
    {
                 return rc = 1;
                 }
                 else
                 {
                     *y = p.c - ((p.b*p.b) / (4*p.a));
                     return rc;
                     }
}


void sort_parabeln(struct parabel *p, int n)
{

   int i, j;
   double y1, y2;
   struct parabel x;

   for (i = 0; i < n - 1; i++){
      if (scheitelhoehe(p[i+1], &y2)==0){
         if(scheitelhoehe(p[i], &y1)==1){
            x = p[i+1];
            p[i+1] = p[i];
            p[i] = x;
            i = 0;
         }else{
            if(y2 < y1){
               x = p[i+1];
               p[i+1] = p[i];
               p[i] = x;
               i = 0;
            }
         }
      }
   }
}

int main() {

   struct parabel p[] = {

      {1,2,3}, // 2

      {2,5,-19}, //-22

      {0,0,0},

      {-1,0,0} // 0
   };

   double y;

   printf("Index 1 ist eine echte Parabel: %d\n", scheitelhoehe(p[0], &y) == 0);

   sort_parabeln(p, sizeof(p) / sizeof(struct parabel));
   return 0;

}