I have to do an assignment where I have to write a C-Programm, where it gets the input-file-name from the console as command line parameter.
It should move the data from the input.txt file (the input file has the information for the bmp file - color etc.) to the generated output.png file. The 20 20 parameters stand for width and height for the output.png image.
So the console-request for example (tested on Linux) will look like this:
./main input.txt output.bmp 20 20
I know that this code reads an input.txt File and puts it on the screen.
FILE *input;
int ch;
input = fopen("input.txt","r");
ch = fgetc(input);
while(!feof(input)) {
putchar(ch);
ch = fgetc(input);
}
fclose(input);
And this would (for example) write it to the output.png file.
FILE *output;
int i;
output = fopen("ass2_everyinformationin.bmp", "wb+");
for( i = 0; i < 55; i++)
{
fputc(rectangle_bmp[i], output);
}
fclose(output);
But this code works only, if I hard-code the name directly in the code, not by using a command line parameters.
I don't have any clue, how to implement that and I also didn't find any helpful information in the internet, maybe someone can help me.
Greetings
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…