My problem is like this: I have to read a file which contains some string. The task is to read data and store in appropriate data structures in a C program.
Currently my program prints all values but accessing these variable is a problem ...
using namespace std;
int split(char* str, char splitstr[15][10]);
int main ()
{
FILE *fp;
char str[20] = {0}; // temp variable for accessing a line from file
// for opening of file
fp = fopen("C:\\Cross Crystal Sheet.csv", "r") ;
char input[256];
char result[15][10];
char *protein[700];
char p[1000];
int j=0;
if (NULL != fp)
{
while(fgets(str,sizeof(str),fp)!=NULL)
{
strcpy(input, str);
int count = split(input, result);
int tmp=count;
//j=result[0]-'0';
for (int i=0; i<count; i++)
{
printf("%s\n", result[i]);
//printf("%s\n",*(result+i));
protein[j]=*(result+i);
//*((protein)+j);
printf("%s \n",*(protein+j));
j++;
}
}
}
}
int split(char* str, char splitstr[15][10])
{
char* p;
int i=0;
char *string = strdup(str);
p = strtok (string, ",");
// i=i+count;
while(p!=NULL)
{
strcpy(splitstr[i++], p);
p = strtok (NULL, ",");
if( p ==NULL)
{
break;
}
unsigned charlength = strlen(p);
if(charlength==1 ||charlength==2 )
{
break;
}
}
return i;
}
I am expecting output like this protein[]={1,ABL1,ABL2,AURKA,AURKB,...}
Data file is like this:
1,ABL1,ABL2,,,,
,,AURKA,,,,
,,AURKB,,,,
,,BMX,,,,
,,BTK,,,,
,,KIT,,,,
,,LCK,,,,
,,MAPK14,,,,
,,PRKACA,,,,
,,SYK,,,,
,,EGFR,,,,
,,INSR,,,,
,,MAPK11,,,,
,,,,,,
2,ABL2,ABL1,,,,
,,AURKA,,,,
,,AURKB,,,,
,,CAMK4,,,,
,,CDKL2,,,,
,,CLK3,,,,
,,CSNK1G3,,,,
,,KIT,,,,
,,LCK,,,,
,,MAPK14,,,,
,,PRKACA,,,,
,,SLK,,,,
,,SYK,,,,
,,,,,,
3,ACVR1,ACVR2A,,,,
,,ACVRL1,,,,
,,PIM1,,,,
,,PRKAA2,,,,
,,,,,,
4,ACVR2A,ACVR1,,,,
,,CAMK2D,,,,
,,MST4,,,,
,,PRKAA2,,,,
,,SLK,,,,
,,,,,,
5,AKT1,PRKACA,,,,
,,,,,,
,,,,,,
6,ALK,FES,,,,
,,MET,,,,
,,,,,,
7,AURKA,ABL1,,,,
,,ABL2,,,,
,,AURKB,,,,
,,CDK2,,,,
,,CHEK1,,,,
,,PLK1,,,,
,,PRKACA,,,,
,,,,,,
8,AURKB,ABL1,,,,
,,ABL2,,,,
,,AURKA,,,,
,,PRKACA,,,,
,,,,,,
9,BMX,ABL1,,,,
,,BTK,,,,
,,LCK,,,,
,,MAPK14,,,,
,,,,,,
10,BRAF,CDK8,,,,
,,KDR/VEGFR2,,,,
,,MAPK14,,,,
,,RAF,,,,
,,,,,,