Can someone help me with Struct Pointers....compile errors
Hi,
I have the following code.... when I try to complile I get a huge amount of errors. I'm not sure why?? It looks right to me?? The program is pretty obvious what I am trying to do.... Sum vectors. Any help is greatly appreciated.
Code:
#include <stdio.h>
Struct Vector{
int size; //global
float * data;
};
#include <stdio.h>
Void AllocVector (struct Vector *VP int n)
{
VP -> size = N;
VP -> data = malloc (N *sizeof float);
}
Void FreeVector (struct Vector *VP)
{
free (VP-> data);
}
int SumVector (struct vector * V)
{
int sum = 0;
int i;
for (i=0; i < v->size; i++) {
sum += v->data[i]; }
return sum;
}
main ()
{
struct Vector v1;
const int N = 100;
AllocVector(&v1, N);
if (v1->data != NULL) {
v1->data[0] = 3.14;
v1->data[1] = 3.15;
}
int sum = SumVector(&v1);
FreeVect(&v1);
}