I have a lab at Clemson that we have to construct a C program that produces the respective images of flags (France, North Rhine, Westphalia, Gibon). Basically the outcome is to have a program that when the country code is entered (0,1,2, or 3) it will display the flag of the country*. "If" statements cannot be in "While" loops, "While" loops cannot be in "While" loops, and "While" loops cannot be in "If" statements. I've been at it for a few hours now, looking through the book and google searches. I'm incredibly frustrated because I have no idea where to start, largely due to my frustration.
This is the main () function that we are supposed to use.
Code:
#include <stdio.h>
P6
800 600 255\n
int main ()
{
int width;
int country_code;
{
//Read image dimensions and pixel color ~~**
}
fscanf(stdin, "%d %d", &country_code, &width);
fprintf(stderr, "Making Country %d width %d \n", country_code, width);
{
//write the image data.......... ~~***
}
make_ppm_image(country_code, width);
return 0;
}
Questions--
*How am I going to tell the program to separate the colors vertically as opposed to horizontally?
**To determine the dimensions of each flag, I'm assuming based on the country code, is this going to be just one single four part if/else statement? such as if country_code = 1, then width = 400 and height = 300; else if country_code=2, then width = 400, height =250 ??
***I have no idea, we haven't touched on this in lecture. But the lab says that we are supposed to use the make_pixel() and make_ppm_header() and gives us this
Code:
void make_pixel (
int r,
int g,
int b)
{
fprintf(stdout, "%c%c%c", r, g, b);
}
______________________________________
void make_ppm_header (int width, int height)
{
fprintf(stdout, "P6\n");
fprintf(stdout, "%d%d%d\n", width, height, 255);
}
I really just don't know what else to ask. All I've come up with on my own is
Code:
France
fprintf(stdout, "%c%c%c", 0,0,255);
fprintf(stdout, "%c%c%c", 255,255,255);
fprintf(stdout, "%c%c%c", 255,0,0);
North Rhine
fprintf(stdout, "%c%c%c", 0,255,0);
fprintf(stdout, "%c%c%c", 255,255,255);
fprintf(stdout, "%c%c%c", 255,0,0);
Westphalia
fprintf(stdout, "%c%c%c", 255,255,255);
fprintf(stdout, "%c%c%c", 0,0,255);
Gabon
fprintf(stdout, "%c%c%c", 0,255,0);
fprintf(stdout, "%c%c%c", 255,255,0);
fprintf(stdout, "%c%c%c", 0,0,255);
fscanf(stdin, "%c%c%c", &r,&g,&b);
, not much of which has anything to do with anything. Either way, I'm not asking for code in as a response, maybe just a better explanation of something I can look up in the book to give me a better idea of what I'm supposed to do?? Everything I've tried to google comes back with programs that pull up existing images, not creating new ones. Usually I can look at code, read the book and between the two say "Oh, I see what you did there" but I can't here because I literally don't know what to ask.
Not to mention I have no idea how I'm gonna construct this without "While" loops in if/else and vice verse -_-.
I know that this is a really long, broad, unintelligible post. I apologize, it's just that I'm too lost to come up with a logical question and I've been at school all morning and work all day, My brain is obliterated. Thanks for any patience and responses.
Robert