Reputation: 13
I'm trying to compile some code but I keep getting the error:
unknown type name ‘ label’;
I've declared these structures inside main, I'm not sure why I'm getting this. I'm declaring each function prototype before the main, then function declarations after main.
I think I remember doing this, shouldn't I be able to? I'm not sure how I would declare these structs earlier.
My code:
void greyScale(Image* image);
void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);
void strech(Image* image);
void findEffect(Image* image,char effect[20]);
int main(int argc, char **argv)
{
char effect[20];
/*file i/o stuff*/
typedef struct Pixel{
int red;
int green;
int blue;
} Pixel;
typedef struct Imagem{
int width;
int height;
Pixel **pixel;
} Image;
Image *image;
/*reads files, calls functions etc..*/
return 0;
}
void greyScale(Image* image)
{
/*code*/
}
void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);
{
/*code*/
}
void strech(Image* image);
{
/*code*/
}
void findEffect(Image* image,char effect[20]);
{
/*code*/
}
Upvotes: 0
Views: 1253
Reputation: 479
Check out this reference C_structures
Move you typedefs outside
typedef struct Pixel{
int red;
int green;
int blue;
} Pixel;
typedef struct Imagem{
int width;
int height;
Pixel **pixel;
} Image;
void greyScale(Image* image);
void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);
void strech(Image* image);
void findEffect(Image* image,char effect[20]);
Upvotes: 3
Reputation: 225817
You define your structs inside of main
, so they're only viewable in that function. These definitions need to be at the top level.
typedef struct Pixel{
int red;
int green;
int blue;
} Pixel;
typedef struct Imagem{
int width;
int height;
Pixel **pixel;
} Image;
void greyScale(Image* image);
void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);
void strech(Image* image);
void findEffect(Image* image,char effect[20]);
int main(int argc, char **argv)
{
...
}
...
Now they're defined before they're used so they are available.
Upvotes: 0