#include <stdio.h>
#include<string.h>
struct node
{
char data[10];
struct node *link;
};
typedef struct node NODE;
#define NULL 0
NODE *head,*p,*q;
main()
{
char ch;
int k, i;
int flag;
char num[10],string[10];
FILE *fp;
char infile[10];
printf("Enter the infile name:\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL)
{
printf("cannot open infile\n");
exit(0);
}
else
{
while(!feof(fp))
{
ch=fgetc(fp);
if(ch==''||ch=='\t'||ch=='\n');
else if((ch>='a'&&ch<='z') || (ch>='A'&&ch<='Z') )
{
p=(NODE*)malloc(sizeof(NODE));head=p;
string[0]=ch;
ch=fgetc(fp);
i=1;
while((ch>='a'&&ch<='z') || (ch>='A'&&ch<='Z')||ch>='0'&&ch<='9')
{
string[i]=ch;
i++;
ch=fgetc(fp);
}
string[i]='\0';
/*printf("%s\n",string);*/
/* p=(NODE*)malloc(sizeof(NODE));head=p;*/
{
q=(NODE*)malloc(sizeof(NODE));
strcpy(q->data,string);q->link=NULL;
printf("%s\n",q->data);
p->link=q;p=q;
}
}
if(ch>='0'&&ch<='9')
{
num[0]=ch;
ch=fgetc(fp);
k=1;
while(ch>='0'&&ch<='9')
{
num[1]=ch;
k++;
ch=fgetc(fp);
}
num[k]='\0';
printf("%s\n",num);
}
}
return(head);
head=head->link;
while(head!=NULL)
{printf("%d.",head->data);
head=head->link;}
}
}
评论0