1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include<stdio.h>
#include<conio.h>
#include<string.h>
FILE *pf;
typedef struct element{
char idf[10];
char type[15];
int valeur;
} point;
point tds[20];
int main()
{
char sym;
char mot[8]="";
int i=0,j=0;
pf=fopen("c:/test.txt","r");
sym=fgetc(pf);
while (sym!=EOF)
{
while (sym!=' ')
{
mot[i]=sym;
i++;
sym=fgetc(pf);
}
if(strcmp(mot,"var")==0)
{
sym=fgetc(pf);
memset(mot,0,sizeof(mot));
}
i=0;
while(sym!=':')
{
mot[i]=sym;
i++;
sym=fgetc(pf);
}
strcpy(tds[0].idf,mot);
printf("%s\n",tds[0].idf);
memset(mot,0,sizeof(mot));
i=0;
while (sym!=';')
{
sym=fgetc(pf);
mot[i]=sym;
i++;
}
strcpy(tds[0].type,mot);
printf("%s",tds[0].type);
}
} |