我有一道题目,要求建立一个索引,然后我想用链表或数组从txt导入数据 |
|
急死我了 我QQ598505282 在线等!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
100分 |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> char *DNA; char ln[200]; char st[200]; FILE *f; int i,n; int main() { DNA=(char *)calloc(1000000*200,1); if (null==DNA) { printf("Can not calloc 1000000*200 bytes!\n"); return 1; } f=fopen("in.txt","r"); if (NULL==f) { printf("Can not open file in.txt!\n"); return 2; } i=0; while (1) { if (NULL==fgets(ln,200,f)) break; if (1==sscanf(ln,"%199[ACGT]",st)) { strcpy(DNA+i*200,st); i++; if (i>=1000000) break; } } fclose(f); n=i; for (i=0;i<n;i++) printf("%s %d\n",i+1,DNA+i*200); free(DNA); return 0; } |
第32行
for (i=0;i<n;i++) printf(“%s %d\n”,i+1,DNA+i*200); 应改为 for (i=0;i<n;i++) printf(“%s %d\n”,DNA+i*200,i+1); |
|
ls的写的有点问题啊?????求解决 也给分!!
C:\Users\Administrator\Desktop\东北赛\编写尝试\索引\solexa.c(12) : error C2065: “”null”” : undeclared identifier C:\Users\Administrator\Desktop\东北赛\编写尝试\索引\solexa.c(12) : warning C4047: “”==”” : “”int “” differs in levels of indirection from “”char *”” |
|
大写字母部分只包含字母:ACGT?
|
|
把null改为NULL,就行了 |
|
#include<stdio.h> #include<malloc.h> int main() { int invalidnum; int id,len; char *val=NULL; FILE *file=fopen("in.txt","r"); if(!file) { fputs("Can""t open file in.txt",stderr); return 1; } else { while(fscanf(file,">read_%d_%d_%d random_genome_%d %d %d\n",&invalidnum,&id,&invalidnum,&invalidnum,&invalidnum,&len)!=EOF) { char *tval=(char*)realloc(val,sizeof(char)*++len); if(!tval) { if(val)free(val); fclose(file); fputs("No memory can be allocated",stderr); return 2; } val=tval; fgets(val,len,file); printf("%s\t%d\n",val,id); fgetc(file); } if(val)free(val); fclose(file); } return 0; } |
|
谢谢斧正! |
|
见你的另一帖子,我的回复
|