【发布时间】:2013-11-24 07:40:47
【问题描述】:
这是某人的程序,我的项目需要它来收集数据。我无法理解命令#define IMAGE argv[1]#define IFS argv[2] 指向的位置以及在IMAGE 和IFS 中定义的值是什么。这两个命令是必要的,因为它们稍后会用于读取文件名。
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <alloc.h>
#define IMAGE argv[1]
#define IFS argv[2]
get_image(FILE *ifs_file, unsigned int *assumed_width_of_image, unsigned int
*assumed_height_of_image, unsigned int *width_of_image, unsigned int *height_of_image, char *argv[]);
unsigned int *image;
main(int argc, char *argv[])
{
unsigned char dom[4][4], d1[4][4], ran[8][8], lowest_error, sym, bestsym, domain_whites,range_whites;
unsigned int assumed_width_of_image, assumed_height_of_image, width_of_image,
height_of_image;
unsigned long int count, domx, domy, ranx, rany, bestranx;
time_t start_time;
FILE *ifs_file;
start_time = time(NULL);
if (argc != 3) {
printf("\nUse the following format:\n\ncompress [image_file] [ifs_file]\n\n");
exit
}
if ((ifs_file = fopen(IFS, "wb")) == NULL) {
fprintf(stderr, "\nError opening file %s\n", IFS);
exit(1);
}
get_image(ifs_file, &assumed_width_of_image, &assumed_height_of_image, &width_of_image, &height_of_image, argv);
get_image(FILE *ifs_file, unsigned int *assumed_width_of_image, unsigned int
*assumed_height_of_image, unsigned int *width_of_image, unsigned int *height_of_image, char *argv[])
{
FILE *image_file;
unsigned int buf[24], *header, size_of_header, extra_height;
unsigned long size_of_file, size_of_image;
if ((image_file = fopen(IMAGE, "rb")) == NULL) {
fprintf(stderr, "\nCannot open file %s\n", IMAGE);
exit(1);
}
if (fread(buf, sizeof(unsigned int), 24, image_file) != 24) {
fprintf(stderr, "\nError reading file %s\n", IMAGE);
exit(1);
}
if (buf[0] != 19778) {
printf("%s is not a .BMP file", IMAGE);
exit(0);
}
if (buf[23] != 2) {
printf("%s is not a black and white image", IMAGE);
exit(0);
}
【问题讨论】:
标签: c