此小程序用win-tc编译运行不了,求高手赐教
#include <stdio.h>#include <stdlib.h>
#include <conio.h>
#define CHIPSTRLEN 20
#define MAXSTRLEN 80
struct CAD
{
char ChipLayout[CHIPSTRLEN];
float x;
float y;
float angle;
char name[MAXSTRLEN];
}*pCAD=NULL;
int chip_dot;
long GetFileLines(char *filename)
{
char c=0,n=0;
long l=0;
FILE *fp;
if((fp=fopen(filename,"r"))==NULL) return -1;
while((c=fgetc(fp))!=EOF)
{
if(n&&n!='\n'&&c=='\n') l++;//Ignore emply lines
n=c;
}
if(n!='\n'&&c==EOF) l++;//if the last line not includes newline character,the value
// of "l" must add 1;
fclose(fp);
return l;
}
void ReadCADFile(char *cadfile)
{
int i=0;
FILE *fp;
fp=fopen(cadfile,"rt");
if(fp==NULL) return;
chip_dot=(int)GetFileLines(cadfile);
if(chip_dot==0||chip_dot==-1) return;
pCAD=(struct CAD *)malloc(sizeof(struct CAD)*chip_dot);
for(i=0;i<chip_dot;i++)
fscanf(fp,"%s%f%f%f%s",pCAD[i].ChipLayout, &pCAD[i].x,&pCAD[i].y,&pCAD[i].angle,pCAD[i].name);
fclose(fp);
}
int main()
{
int i;
ReadCADFile("cad.txt");//cad.txt 见附件
cad.rar
(2.08 KB)
for(i=0;i<chip_dot;i++)
printf("%s %.2f %.2f %.2f %s\n",pCAD[i].ChipLayout, pCAD[i].x,pCAD[i].y,pCAD[i].angle,pCAD[i].name);
getch();
return 0;
}