修改可读取压缩格式文件
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <zlib.h> 5 6 #define RLEN 1024 7 8 static void getfq(char *fq); 9 10 int main(int argc, char *argv[]){ 11 12 if(argc!=2){ 13 fprintf(stderr," usage: %s fastq[.gz] ",argv[0]); 14 exit(-1); 15 } 16 getfq(argv[1]); 17 exit(0); 18 } 19 20 static void getfq(char *fq){ 21 22 gzFile fp1=gzopen(fq,"r"); 23 char fline[RLEN]; 24 char read[4][RLEN]; 25 char *r=NULL; 26 27 while(fp1 != NULL){ 28 for(int i=0; i<4; i++){ 29 r=gzgets(fp1,fline,RLEN); 30 if(r != NULL){ 31 strcpy(read[i],fline); 32 } 33 else{ // EOF 34 goto LoopOut; 35 } 36 } 37 for(int i=0; i<4; i++){ 38 if(i==0){ 39 memcpy(read[i],">",1); 40 fprintf(stdout,"%s",read[i]); 41 } 42 else if(i==1){ 43 fprintf(stdout,"%s",read[i]); 44 } 45 else{ 46 continue; 47 } 48 } 49 } 50 LoopOut: 51 free(r); 52 r=NULL; 53 gzclose(fp1); 54 55 return; 56 }