Hi,
I have to write a program that basically takes in values and spits out it's mirror. What I mean is for example if the data is 123 the output would 123321, it prints itself and then itself backwards. This is part of a larger program....I will put in what I have....I know I'm close I'm getting a few compile errors....I just need a little help to get over this help.
Code:
struct Vector {
int size;
float *data;
};
void AllocVector (struct Vector *VP, int n)
{
VP->size = n;
VP->data = malloc(n * sizeof(float));
if(VP->data == NULL)
{
fprintf(stderr, "Memory allocation failed\n");
exit(1);
}
}
struct Vector Mirror (struct Vector v)
{
struct Vector *mirror;
int i = 0;
int j = 0;
AllocVector(mirror,v.size + v.size);
for (i=0; i<v.size; i++)
{
v.mirror[i] = v.data[i];
//v.data[i] = mirror[i];
}
j = i;
for (i=v.size-1; i>=0; i--)
{
{
mirror[j] = v.data[i];
j++;}
return mirror;
}
The compile errors I get are the following the refer to the assignment of mirror[i] to v.data[i] as well as j and the return. any help is greatly appreciated
Code:
vectora.c:84: incompatible types in assignment
vectora.c:91: incompatible types in assignment
vectora.c:94: incompatible types in return