c – 调试器跳过整个if语句
发布时间:2020-12-16 10:07:18 所属栏目:百科 来源:网络整理
导读:/** * Copies a BMP piece by piece,just because. * All we have to do is change all the red pixels to */#include stdio.h#include stdlib.h#include "bmp.h"int main(int argc,char *argv[]){ // ensure proper usage if (argc != 3) { fprintf(stderr,
/** * Copies a BMP piece by piece,just because. * All we have to do is change all the red pixels to */ #include <stdio.h> #include <stdlib.h> #include "bmp.h" int main(int argc,char *argv[]) { // ensure proper usage if (argc != 3) { fprintf(stderr,"Usage: ./copy infile outfilen"); return 1; } // remember filenames char *infile = argv[1]; char *outfile = argv[2]; // open input file FILE *inptr = fopen(infile,"r"); if (inptr == NULL) { fprintf(stderr,"Could not open %s.n",infile); return 2; } // open output file FILE *outptr = fopen(outfile,"w"); if (outptr == NULL) { fclose(inptr); fprintf(stderr,"Could not create %s.n",outfile); return 3; } // read infile's BITMAPFILEHEADER BITMAPFILEHEADER bf; fread(&bf,sizeof(BITMAPFILEHEADER),1,inptr); // read infile's BITMAPINFOHEADER BITMAPINFOHEADER bi; fread(&bi,sizeof(BITMAPINFOHEADER),inptr); // ensure infile is (likely) a 24-bit uncompressed BMP 4.0 if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || bi.biBitCount != 24 || bi.biCompression != 0) { fclose(outptr); fclose(inptr); fprintf(stderr,"Unsupported file format.n"); return 4; } // write outfile's BITMAPFILEHEADER fwrite(&bf,outptr); // write outfile's BITMAPINFOHEADER fwrite(&bi,outptr); // determine padding for scanlines int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; // iterate over infile's scanlines for (int i = 0,biHeight = abs(bi.biHeight); i < biHeight; i++) { // iterate over pixels in scanline for (int j = 0; j < bi.biWidth; j++) { // temporary storage RGBTRIPLE triple; // read RGB triple from infile fread(&triple,sizeof(RGBTRIPLE),inptr); RGBTRIPLE red = {0,255}; int same = 0; RGBTRIPLE white = {255,255,255}; if(&red.rgbtRed == &triple.rgbtRed && &red.rgbtGreen != &triple.rgbtRed && &red.rgbtBlue != &triple.rgbtRed) { same = 1; } if(same == 0) //copy the pixel,if the pixel isn't red { // write RGB triple to outfile fwrite(&triple,outptr); } if(same == 1) { fwrite(&white,outptr); } } // skip over padding,if any fseek(inptr,padding,SEEK_CUR); // then add it back (to demonstrate how) for (int k = 0; k < padding; k++) { fputc(0x00,outptr); } } // close infile fclose(inptr); // close outfile fclose(outptr); // success return 0; } 我的问题更具体地说是这段代码: // temporary storage RGBTRIPLE triple; // read RGB triple from infile fread(&triple,outptr); } 我试图将bmp文件复制到另一个文件,但摆脱任何红色并用白色替换它(大部分代码不是我的工作,我应该为编辑编写的预编写代码),副本功能有效,但由于某种原因检测到红色并用白色替换它不起作用.奇怪的是,当我使用调试器时,它完全跳过了这部分代码: if(&red.rgbtRed == &triple.rgbtRed && &red.rgbtGreen != &triple.rgbtRed && &red.rgbtBlue != &triple.rgbtRed) { same = 1; } 这是我检测像素是否为红色的地方,调试器的作用就好像该行不存在一样. 解决方法
不要比较地址,你根本不需要使用int相同的变量.
if(red.rgbtRed == triple.rgbtRed && red.rgbtGreen != triple.rgbtRed && red.rgbtBlue != triple.rgbtRed) { fwrite(&white,outptr); } else { fwrite(&triple,outptr); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – (如何)可以绑定/重新绑定一个方法来处理不同签名的代
- swift – UI测试失败 – 元素和任何后代都没有键盘焦点在Te
- ruby-on-rails – 中间件如何被删除?
- Oracle 11g dmp导入. ORA-39000 / ORA-39143错误
- 请实现一个函数用来匹配包括'.'和'*'的正则
- ruby – 使用strong_parameters序列化数组
- xml引用本地或网络xsd,xsd命名空间解释
- react-native初探——helloworld demo
- ruby-on-rails – Lua on Rails?
- c# – Intellitest / Pex正在尝试为对象中的私有只读字典字