i have a cgi program in c, which serves an jpeg file. it works, but i thought it needs fread and fwrite for binary files. can you tell me why it works here for binary file with getc and putc? these functions i thought are only for text files?
#include <stdio.h>
int main(){
printf("Content-type: image/jpeg\n\n");
FILE* fp=fopen("../protected/DSCN2099.JPG","rb");
int ch;
while(1){
ch=getc(fp);
if(ch==EOF){
break;
}
putc(ch,stdout);
}
fclose(fp);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire