나는 파일에서는 내가 보는 이의 시퀀스를 바이트:0xFF,0xD8,0xFF,그리고 0xE0. 을 위해 지금 가정하자 나는 보 0xFF. 이 프로그램에 대한 테스트:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void analyzeFile(char* filename)
{
FILE* filePtr = fopen(filename, "rb");
int numImages = 0;
while (!feof(filePtr))
{
char bytes;
bytes = getc(filePtr);
printf("%c", bytes);
if ((bytes == 0xFF))
{
numImages++;
printf("image found!\n");
}
}
printf("%d\n", numImages);
}
이 작동하지 않습니다. 부를 때 analyzeFile 매개 변수"test.txt"인쇄 파일의 내용을 밖으로 좋은,하지만 감지하지 못하는 단일 0xFF 바이트:
내용 test.txt:
aÿØÿÿà1234
출력:
aÿØÿÿà1234
0
에 대한 참조,0xFF 에 해당하 y 분음기호,ÿ 에 따라,ASCII.
(char)bytes
으로 매개 변수printf
쓸모없는? 그것을 얻을 것이 casted 시int
기본 프로모션이다.