I'm new to C coming from Python/Perl background.
I'm writing a C program that will create multiple outputs and the number of outputs is determined from a input description file (basically the number of lines in the description file is the number of outputs) and one ID column in the description file will be used as output name.
What I currently have is that I read the ID column from the description file into an array and use the number of IDs to try to open the same number of FILE stream.
I'm having trouble in getting this to work. I have something like this right now and it complains at the compilation with the message at line 82 and 84:
error: variable-sized object may not be initialized
Part of the code:
3 #include <stdio.h>
4 #include <time.h>
5 #include <zlib.h>
6 #include <string.h>
....
50 gzFile fi2,fi1,fr1;
51
52 fi2 = strcmp(argv[1],"-")? gzopen(argv[1],"r"):gzdopen(fileno(stdin),"r");
53 fi1 = strcmp(argv[2],"-")? gzopen(argv[2],"r"):gzdopen(fileno(stdin),"r");
54 FILE *samplelist = fopen(argv[5],"r");
55 fr1 = strcmp(argv[6],"-")? gzopen(argv[6],"r"):gzdopen(fileno(stdin),"r");
56 if (fi2 ==0 || fi1 ==0 || samplelist == 0 || fr1 == 0 ) {
57 fprintf(stderr,"[E:%s] failed to open the input file/stream.\n",__func__);
58 return 1;
59 }
60
61 char line[100];
62 char indexseq[10];
63 char sampleid[5];
64 char genome[15];
65 char seqmode[3];
66 char indexes[10][BUFSIZ];
67 int lidx = 0;
68 while (fgets(line, sizeof(line),samplelist)) {
69 //printf("%s",line);
70 sscanf(line,"%s\t%s\t%s\t%s\n",indexseq,sampleid,genome,seqmode);
71 //printf("%s\n",indexseq);
72 //printf("%s\n",sampleid);
73 strcpy(indexes[lidx],sampleid);
74 ++lidx;
75 strcpy(indexes[lidx],indexseq);
76 ++lidx;
77 }
78 char buf[30] = "";
79 int i;
80 for (i = 0; i <lidx; i+=2) {
81 snprintf(buf, sizeof buf, "%s%s%s%s", argv[3],"_I1_",indexes[i],".fastq");
82 fo_i1[i] = fopen(buf,"w");
83 snprintf(buf, sizeof buf, "%s%s%s%s", argv[3],"_R1_",indexes[i],".fastq");
84 fo_r1[i] = fopen(buf,"w");
85 }
How could I get around the variable-sized FILE streams and get it work? Any suggestions on ways to modify certain lines are also welcome!