我的问题是这样的:我必须读取一个包含一些字符串的文件。任务是在 C 程序中读取数据并存储在适当的数据结构中。
目前我的程序打印所有值,但访问这些变量是一个问题......
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;
}
我期待像这样的蛋白质 []={1,ABL1,ABL2,AURKA,AURKB,...}
数据文件是这样的:
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,,,,
,,,,,,