как-то так:
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
if ( argc < 2 ) {
return 0;
}
FILE *f = fopen( argv[1],"rb");
char buffer[100];
unsigned char lengthBuf[4];
char type[5];
fread(buffer, 1, 8, f);
if ( strncmp("\x89PNG\r\n\x1a\n", buffer, 8 ) ) {
printf("Not a PNG file!\r\n");
fclose(f);
return 0;
};
while(!feof(f)) {
int len = 0;
fread(lengthBuf, 1, 4, f);
len=(lengthBuf[0]<<24)|(lengthBuf[1]<<16) | (lengthBuf[2]<<8) |lengthBuf[3];
fread(type, 4,1, f);
type[4] = 0;
if (strcmp(type, "iTXt") == 0 ) {
char *data = new char[len];
fread(data, len, 1 , f);
data[len] = 0;
char keyword[100];
char* comment = new char[len];
strcpy(keyword, data);
int keywordLen = strlen(keyword);
int i = 0;
while( data[keywordLen + i++ ] == 0);
strcpy(keyword, data);
strcpy(comment, &data[keywordLen+i-1]);
printf("Keyword='%s', text='%s'\r\n", keyword, comment);
delete comment;
delete data;
break;
}
if (strcmp(type, "IEND") == 0 ) {
break;
}
fseek(f, len+4, SEEK_CUR);
}
fclose(f);
return 0;
}