将文件中的数据读入链表中
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
struct name_code
{
struct name_code*pro;
char code[7];
char ge_code_name[600];
struct name_code*next;
};
struct name_code* hhcreat(FILE*name);
struct name_code* hhinsert(struct name_code*hh,FILE*name);
void nspnt(struct name_code *hh);
int main(void)
{
struct name_code *hh=NULL;
FILE*name;
name=fopen("genenname.txt","r");
hh=hhcreat(name);
hh=hhinsert(hh,name);
nspnt(hh);
return 0;
}
struct name_code* hhcreat(FILE*name)
{
struct name_code *hh;
hh=(struct name_code*)malloc(sizeof(struct name_code));
fscanf(name,"%s",hh->code);
char a,b;
a=getc(name);
b=getc(name);
fseek(name,-2L,SEEK_CUR);
if(b!='\n')
{
fscanf(name,"%s",hh->ge_code_name);
}
hh->pro=NULL;
hh->next=NULL;
return hh;
}
struct name_code* hhinsert(struct name_code*hh,FILE*name)
{
struct name_code *node=NULL,*end=NULL;
end=hh;
while(!feof(name))
{
node=(struct name_code*)malloc(sizeof(struct name_code));
fscanf(name,"%s",node->code);
char a,b;
a=getc(name);
b=getc(name);
fseek(name,-2L,SEEK_CUR);
if(b!='\n')
{
fscanf(name,"%s",hh->ge_code_name);
}
node->pro=end;
end->next=node;
end=node;
}
end->next=NULL;
return hh;
};
void nspnt(struct name_code *hh)
{
if(hh==NULL)
{
printf("error!");
return;
}
else
{
while(hh!=NULL)
{
printf("%s %s\n",hh->code,hh->ge_code_name);
hh=hh->next;
}
}
}
下面是文件中的一部分数据
7896736
7896738
7896740 OR4F17///OR4F5///OR4F4
7896742 LOC100134822///LINC00266-1
7896744 OR4F29///OR4F21///OR4F16///OR4F3
7896746
7896748
7896750
7896752
7896754 LOC100287934///LOC100287497
7896756 FAM87A
7896759 LINC01128
7896761 SAMD11///NOC2L
7896779 KLHL17
7896798 PLEKHN1
7896817 ISG15
7896822 AGRN
7896859 MIR200B
7896861 MIR200A
7896863 MIR429
7896865 TTLL10
7896878 B3GALT6
7896882 SCNN1D
7896908 PUSL1///CPSF3L
7896917 CPTP
7896921 TAS1R3
7896929 VWA1
7896937 ATAD3C///ATAD3A
7896952 ATAD3A
7896961 ATAD3B///ATAD3A
7896983
7896985 MIB2
7897006 MMP23A///MMP23B
7897026 CALML6
7897034 GABRD
7897044 PRKCZ
7897066 FAAP20
7897068 SKI
7897076 MORN1
7897078 RER1
7897089 PLCH2
7897119 FAM213B
7897128 ACTRT2
7897132 PRDM16
7897154 ARHGEF16
7897172 TPRG1L///TPRG1L
7897179 TP73
7897196 CCDC27
7897210 DFFB
7897227 AJAP1
7897236 KCNAB2
7897257 RNF207
7897263 RNF207
7897277 LINC00337
7897280 HES3
7897286 LOC100130071
7897288 ESPN
7897295 TAS1R1
7897305 ZBTB48
7897322 PHF13
7897329 THAP3///DNAJC11
7897339 CAMTA1
7897368
调试显示只读入了数字,而没有读入后面的字母
我的问题是不知到怎么判断数字后面是不是有字母
我希望能将文件中的数据读入链表